【发布时间】:2013-03-04 14:25:36
【问题描述】:
我需要通过迁移将属性/列添加到 Heroku.com(Rails 应用程序)上的生产数据库(Postgre)中的表中。 当我进行迁移时,它看起来不错,但是当我查看表上的列时,它还没有添加列!
我的开发数据库是 sqlite3,生产数据库是 postgre
我执行以下操作:
heroku run rails generate migration AddUtc_OffsetToEvents utc_offset:integer RAILS_ENV=production --app app-name-1111
然后它返回:
invoke active_record
create db/migrate/20130304070946_add_utc_offset_to_events.rb
然后我运行迁移
heroku run rake db:migrate RAILS_ENV=production --app app-name-1111
然后:
heroku restart
当我跑步时
heroku pg:psql HEROKU_POSTGRESQL_GRAY_URL --app app-name-1111
并检查表格的列:
\d+ events
它仍然没有 utc_offset 列,并且在执行之前的 cmds 时没有显示任何错误。
有什么想法或提示吗?
【问题讨论】:
-
迁移文件的内容是什么?为什么要在生产环境中创建迁移?你应该先在 dev 中这样做。
-
迁移内容:
class AddUtcOffsetToEvents < ActiveRecord::Migration def change add_column :events, :utc_offset, :integer end end这是必要的,因为在部署到 heroku 之前,在 dev 中完成的迁移没有错误地添加到版本控制中 -
你能不试试
RAILS_ENV=production吗?这可能会在解析命令时搞砸 Toolbelt。在这种情况下,RAILS_ENV=production无论如何都是自动的。heroku run rake db:migrate --app app-name-1111
标签: ruby-on-rails-3 postgresql heroku rails-migrations