Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 可以在postgre数据库的heroku上运行迁移_Ruby On Rails 3_Postgresql_Heroku_Rails Migrations - Fatal编程技术网

Ruby on rails 3 可以在postgre数据库的heroku上运行迁移

Ruby on rails 3 可以在postgre数据库的heroku上运行迁移,ruby-on-rails-3,postgresql,heroku,rails-migrations,Ruby On Rails 3,Postgresql,Heroku,Rails Migrations,我需要通过迁移将属性/列添加到Heroku.com(Rails应用程序)上的生产数据库(Postgre)中的表中。 当我进行迁移时,它看起来不错,但是当我查看表中的列时,它没有添加列 我的开发数据库是sqlite3,生产数据库是postgre 我做了以下工作: heroku run rails generate migration AddUtc_OffsetToEvents utc_offset:integer RAILS_ENV=production --app app-name-1111

我需要通过迁移将属性/列添加到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时不会显示任何错误


有什么想法或提示吗?

看起来您正在多次调用heroku run

每次你运行heroku时,它都会用你最新的代码产生一个全新的dyno,当运行结束时,dyno就会被销毁。因此,第二次heroku运行没有在第一次运行中创建迁移字段


因为您已经熟悉psql,所以可以直接使用
altertable
。否则,您需要检查代码中的迁移,并将heroku master推送到heroku,然后运行它。

为什么不下载代码、添加迁移并推送更改?
之后,只需在应用程序上运行heroku run rake db:migrate。

迁移文件的内容是什么?为什么要在生产环境中创建迁移?您应该首先在dev中执行此操作。迁移的内容:
class AddUtcOffsetToEvents
这是必需的,因为在部署到Heroku之前,在dev中完成的迁移没有被错误地添加到版本控制中。您可以尝试不使用
RAILS_ENV=production
?这可能是在解析命令时弄坏了工具带<代码>RAILS_ENV=production
在这种情况下将自动执行<代码>heroku运行rake db:migrate--应用程序app-name-1111检查了到heroku的迁移,然后运行了迁移-谢谢