Rake文件在Heroku上看到旧版本的数据库 [英] Rake file is seeing old version of database on Heroku

查看:156
本文介绍了Rake文件在Heroku上看到旧版本的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rakefile为我的数据库播种。我看到了奇怪的行为(请参阅其他用户属性导致UnknownAttributeError和NoMethodError ),并得出结论,它在我的数据库的旧版本上运行(至少,我的用户表的旧版本,或许更多)。
$ b


  • 在localhost上运行rakefile可以正常工作

  • 在Heroku上,在rakefile中打印User.column_names显示表格的旧版本

  • 在Heroku中,从主应用程序中打印User.column_names以显示表格的新版本

  • 在Heroku内Rails控制台,User.column_names显示表的新版本



任何想法如何解决?

解决方案

确保你在heroku上做的一件事是正确地重新启动你的d​​ynos。我的一个客户曾经尝试过这样的事情:

  heroku run rake db:migrate db:seed_data 

Heroku的文档位于 https://devcenter.heroku.com/articles/rake 提到您应该在迁移之间重新启动您的应用程序:


运行迁移后,您需要使用heroku
重新启动应用程序以重新加载架构并获取任何架构更改。




<所以答案可能是不在相同的过程中进行批处理;即尝试像

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


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?

解决方案

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

这篇关于Rake文件在Heroku上看到旧版本的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆