Rails 3 迁移在 Heroku 上不起作用

发布于 2024-10-20 03:33:40 字数 1022 浏览 1 评论 0原文

我有一个非常简单的迁移,它是使用生成器创建的

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只为一人 2024-10-27 03:33:40

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.

守不住的情 2024-10-27 03:33:40

您是否运行了“heroku rake db:migrate”?这不是在本地运行迁移,而是在 Heroku 上运行。

Did you run "heroku rake db:migrate" ? This runs migrations not locally, but on Heroku.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文