ruby-on-rails - 部署 Rails 应用程序时为 "PG::UndefinedColumn:"

标签 ruby-on-rails ruby postgresql database-migration

使用 Capistrano 将我的更改部署到生产环境时出现错误

PG::UndefinedColumn: ERROR:  column "address_id" of relation "member_applications" does not exist

在我的迁移中我有

class CreateAddresses < ActiveRecord::Migration[5.1]
    def change
        create_table :addresses do |t|
            t.string :full_name, null: false
            t.string :email, null: false
            t.string :phone, null: false
            t.string :address, null: false
            t.string :state, null: false
            t.string :country, null: false
            t.string :postcode, null: false
            t.timestamps
        end
    end
end

class CreateMemberApplications < ActiveRecord::Migration[5.1]
    def change
        create_table :member_applications do |t|
            t.references :location, null: false
            t.references :addresses, null: false
            t.references :user, null: false
            t.string :full_name, null: false
            t.date :birthdate, null: false
            t.timestamps
        end
    end
end

最后

class SetAddressToNull < ActiveRecord::Migration[5.1]
  def change
      change_column_null :member_applications, :address_id, true
  end
end

最后一次迁移似乎是导致问题的原因。是什么导致了这个问题?它一直在我的开发机器上运行,但距离我上次部署已经有一段时间了。

最佳答案

我认为问题出在这里:

create_table :member_applications do |t|
  ...
  t.references :addresses, null: false
  ...
end

应该是 t.references :address, null: false 单数。

你可以检查你的db/schema.rb来验证。

关于ruby-on-rails - 部署 Rails 应用程序时为 "PG::UndefinedColumn:",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47026256/

相关文章:

ruby-on-rails - 在 Rails 中使用 XML 发出 SOAP 请求

ruby-on-rails - bool REST 结果的最佳实践

python - 从 sqlalchemy 更改为 postgresql 并得到关系错误

ruby-on-rails - Rails 3 命名空间路由 : how to link *from* a namespace back to the global namespace? [已修订]

javascript - RAILS 不渲染 js.erb

sql - 对数组中存储的数据进行搜查(运算符不存在 : integer[] = integer)

ruby-on-rails - Rails 4 从多个表中返回与搜索项匹配的记录

ruby - 使用 RSpec 测试输出到命令行

sql - 请推荐最好的批量删除选项

mysql - 在 SQL 中排序时如何保留逻辑分组?