gpt4 book ai didi

ruby-on-rails - PGError : ERROR: relation "table_name" does not exist

转载 作者:数据小太阳 更新时间:2023-10-29 06:47:33 25 4
gpt4 key购买 nike

我正在尝试将一个简单的应用程序推送到 heroku 并运行:

heroku rake db:migrate

但是我得到以下错误:

rake aborted!
PGError: ERROR: relation "posts" does not exist
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"posts"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

我的迁移看起来像这样:

class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :source
t.string :tweetid
t.string :pure
t.string :media
t.string :destination
t.datetime :time
t.timestamps
end
end
end

并且,在引用了另一个 SO 答案之后,我在我的 Gemfile 中包含了以下内容:

# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
gem 'pg'
end

提前感谢您的帮助!

---更新---

我感到困惑的主要原因是这一切都在本地工作,只是当我在 heroku 上运行迁移时不行。

这是我现在得到的错误:

rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)

我一直在看这个问题:

Heroku error when launch rails3.1 app missing postgres gem

我几乎可以肯定我的 database.yml 不应该是这样的(因为我需要运行 postgresql!!!):

# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

对于这里的幼稚行为,我深表歉意。提前感谢您的帮助!

也试过这个链接:Uploading to Heroku DB rake:migrate problem

最佳答案

create_table :posts

你没有忘记 s 吗?表名应该是复数。

关于ruby-on-rails - PGError : ERROR: relation "table_name" does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8392899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com