Rails 5 / postgres:如何将id列从UUID迁移到bigint?

时间:2019-02-23 14:32:39

标签: ruby-on-rails postgresql ruby-on-rails-5

我有一个表,其主键类型为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的正确方法是什么?

0 个答案:

没有答案