Rake file is seeing old version of database on Heroku

元气小坏坏 提交于 2019-12-11 12:40:02

问题


I'm using a rakefile to seed my database. I was seeing weird behavior (see Additional user attributes results in UnknownAttributeError and NoMethodError) and have concluded that it is operating on an old version of my database (at the very least, an old version of my Users table, perhaps more).

  • Running the rakefile on localhost works fine
  • On Heroku, printing User.column_names within the rakefile shows the old version of the table
  • On Heroku, printing User.column_names from within the main app shows the new version of the table
  • Within Heroku rails console, User.column_names shows the new version of the table

Any ideas how to resolve?


回答1:


One thing to make sure you do on heroku is restart your dynos correctly. A client of mine once tried something like this:

heroku run rake db:migrate db:seed_data

Heroku's documentation at https://devcenter.heroku.com/articles/rake mentions that you should restart your app in between migrations:

After running a migration you’ll want to restart your app with heroku restart to reload the schema and pickup any schema changes.

So the answer might be to not batch it in the same process; i.e. try something like

heroku run rake db:migrate; heroku run rake db:seed_data


来源:https://stackoverflow.com/questions/25651125/rake-file-is-seeing-old-version-of-database-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!