【问题标题】:Migration column not created on heroku db, visible on local - Rails迁移列未在 heroku db 上创建,在本地可见 - Rails
【发布时间】:2015-11-07 18:02:27
【问题描述】:

这是迁移文件

class CreateComments < ActiveRecord::Migration
      def change
        create_table :comments do |t|
          t.string :name
          t.string :email
          t.text :body
          t.boolean :spam, default: false
          t.references :post, index: true, foreign_key: true
          t.references :user, index: true, foreign_key: true

          t.timestamps null: false
        end
      end
    end

由于某种原因,没有在 heroku 上创建 user_id 列。

heroku 上的实际表格

Comment(id: integer, name: string, email: string, body: text, post_id: integer, created_at: datetime, updated_at: datetime)

我已经尝试过heroku restart,也许它会更新架构或其他东西,但什么也没有。

在我的本地环境中,我可以看到并且可以使用 user_id 列。

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 heroku ruby-on-rails-3.2


    【解决方案1】:

    我想您修改了现有迁移,而不是创建新迁移。

    您需要在 Herokurollback 进行迁移,然后再次 migrate 进行迁移。

    请记住,您必须为您的存储库创建两个提交,一个没有修改,然后继续。这是因为在回滚迁移时,添加的列应该会丢失,否则它会尝试删除不存在的列。

    所以过程如下:

    1. 从迁移中删除修改。提交更改。
    2. heroku run rake db:rollback STEP=1 或您需要的许多步骤。
    3. 再次添加修改。提交更改。
    4. heroku run rake db:migrate

    【讨论】:

      【解决方案2】:

      尝试以下操作 - 我猜这是您的最后一次迁移 -

      heroku run rake db:rollback 回滚上次迁移

      heroku run rake db:migrate 再次运行迁移

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-03
        • 2018-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多