【问题标题】:Rails 5.0 to 5.2: how to migrate schema.rbRails 5.0 到 5.2:如何迁移 schema.rb
【发布时间】:2018-10-18 17:11:00
【问题描述】:

更新我的 gem 后,我无法运行 rails db:schema:load。报错是:

ActiveRecord::MismatchedForeignKey: Column `user_id` on table 
`user_applications` has a type of `int(11)`.
This does not match column `id` on `users`, which has type 
`bigint(20)`.

这与从 rails 5.2(或 rails 5.1,我不知道)更改主键的一些默认 int 类型有关。我的问题是:我应该如何“迁移”数据库/模式?或者,我可以将主键设置为 32 位整数吗?因为我已经在application.rb试过了:

config.generators do |generator|
  generator.orm :active_record, primary_key_type: :integer
end

但在运行上述任务时它没有做任何事情。

【问题讨论】:

    标签: ruby-on-rails rails-migrations ruby-on-rails-5.1 ruby-on-rails-5.2


    【解决方案1】:

    移动旧方案文件并创建一个新文件:

    $ rails db:schema:dump 
    

    【讨论】:

    • 谢谢!它有点工作,但发生了一些奇怪的事情:文本列中的:limit 字段被删除,using: :btree 也被删除(我想这是设计使然),外键声明(add_foreign_key 调用)消失了,是这是预期的?
    • 很难知道,我们能看到你的迁移文件吗?
    • 我认为这与迁移文件无关(我只想迁移 schema.rb)。但是add_foreign_key电话消失确实很奇怪。
    猜你喜欢
    • 2013-12-26
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2016-08-07
    • 1970-01-01
    • 2011-12-12
    • 1970-01-01
    相关资源
    最近更新 更多