Rails 3 迁移在 Heroku 上不起作用
我有一个非常简单的迁移,它是使用生成器创建的
class AddEmailToUsers < ActiveRecord::Migration
def self.up
add_column :users, :email, :string
end
def self.down
remove_column :users, :email
end
end
,它在本地运行得很好
rake db:migrate
rails console
>> User.column_names
=> ["id", "created_at", "updated_at", "uid", "provider", "name", "role", "email"]
,我在 Heroku 上有两个版本的应用程序。一方面,它工作得很好。在另一种情况下,该列根本不显示。
heroku rake db:migrate 的输出看起来是正确的:
== AddEmailToUsers: migrating ================================================
-- add_column(:users, :email, :string)
-> 0.0031s
== AddEmailToUsers: migrated (0.0032s) =======================================
但是该列不存在:(
>> User.column_names
=> ["id", "created_at", "updated_at", "uid", "provider", "name", "role"]
顺便说一句,我所有的数据库更改都是通过生成器创建的迁移进行的;我自己没有接触过 SQL,也没有编辑过任何迁移文件。)
这是生产环境,因此不能选择删除表。
对我可以尝试的事情有什么建议吗?
I have a very simple migration which was created using the generator
class AddEmailToUsers < ActiveRecord::Migration
def self.up
add_column :users, :email, :string
end
def self.down
remove_column :users, :email
end
end
It works great locally
rake db:migrate
rails console
>> User.column_names
=> ["id", "created_at", "updated_at", "uid", "provider", "name", "role", "email"]
I have two versions of the app on Heroku. In one, it works fine. In the other, the column simply doesn't show up.
The output from heroku rake db:migrate looks right:
== AddEmailToUsers: migrating ================================================
-- add_column(:users, :email, :string)
-> 0.0031s
== AddEmailToUsers: migrated (0.0032s) =======================================
But the column isn't there:
>> User.column_names
=> ["id", "created_at", "updated_at", "uid", "provider", "name", "role"]
(By the way, all my database changes have been via generator-created migrations; I haven't touched SQL myself nor edited any migration files.)
This is a production environment so dropping the table is not an option.
Any suggestions for things I can try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
heroku restart
为我解决了这个问题。
我认为这是heroku系统中的一个错误。我刚刚给他们发了电子邮件要求修复。
heroku restart
fixes the issue for me.
I think this is a bug in the heroku system. I've just emailed them asking for a fix.
您是否运行了“heroku rake db:migrate”?这不是在本地运行迁移,而是在 Heroku 上运行。
Did you run "heroku rake db:migrate" ? This runs migrations not locally, but on Heroku.