我有一个表,其主键类型为UUID。
我想创建一个迁移,以便安装bigint
。我的迁移看起来像这样:
class ChangePrimaryKeyToBigintOnProjects < ActiveRecord::Migration[5.2]
def change
change_column :projects, :id, :bigint, unique: true, null: false, auto_increment: true
end
end
但是,postgres抱怨并且迁移失败。
PG::DatatypeMismatch: ERROR: column "id" cannot be cast automatically to type bigint
也可以提供提示:
HINT: You might need to specify "USING id::bigint".
但是如何使用该语句?我似乎无法将其传递给change_column
。 (不是我可以从文档中看出来的。)
将主密钥从UUID迁移到bigint
的正确方法是什么?