我使用 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)