开发者

How can I run a migration on my production database but not my development database?

I have a development database on my computer and a production database on Heroku. I need to run a migration on the production database, to c开发者_运维百科lear certain data, that I don't want to run on the development one. So far I've only been doing migrations that I've wanted to run on both, so I just create it on my computer, run it, then when I upload to Heroku I run it on there too. How can I do a migration only on the production database? Thanks for reading.


  1. Create your migration.
  2. Commit, push, run on heroku with heroku rake db:migrate --app myapp.
  3. Comment out the contents of the up block.
  4. Run the (now-empty) migration locally.
  5. Uncomment or git checkout/reset to get back to normal.

This way both your local db and production db will consider the migration to have been run and not try to run it again.


Migrations are intended to update the structure of your database, not to manipulate data. If you want to manipulate data, you should use the console or a script.

$ heroku console


RAILS_ENV=production rake db:migrate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜