【发布时间】:2012-01-13 15:23:13
【问题描述】:
我正在尝试将一个简单的应用程序推送到 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
对于此处的不雅内容,我们深表歉意。提前感谢您的帮助!
【问题讨论】:
-
gem 'pg' 应该在 group :assets 块之外,我认为它与它无关。你试过
heroku rake db:setup吗? -
heroku 的 gemfile 中不需要 pg
-
抱歉,这是一个较早的实验,看看复数是否影响了它。
-
有同样的问题.. 不会 rake db:setup 删除所有现有数据?
标签: ruby-on-rails ruby ruby-on-rails-3 postgresql heroku