小编Kir*_*nik的帖子

为什么 Rails 迁移失败?

我使用 uuid 而不是 bigint 作为主键。和下一次迁移

class CreateProjects < ActiveRecord::Migration[6.0]
  def change
    create_table :projects, id: :uuid do |t|
      t.string :title
      t.references :user, null: false, foreign_key: true
      t.timestamps
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

失败并出现错误:

PG::DatatypeMismatch: ERROR:  foreign key constraint "fk_rails_b872a6760a" cannot be implemented
DETAIL:  Key columns "user_id" and "id" are of incompatible types: bigint and uuid.
Run Code Online (Sandbox Code Playgroud)

postgresql uuid ruby-on-rails database-migration

4
推荐指数
1
解决办法
500
查看次数