我有一个Rails应用,其中的列名为cancel
当我将其从string
更改为boolean
时,我进行了2次迁移
此迁移首先运行:
class AddCancelToUser < ActiveRecord::Migration[5.1]
def change
add_column :users, :cancel, :string
end
end
然后这个:
class Changetype < ActiveRecord::Migration[5.1]
def change
change_column :users, :cancel, :boolean, default: false
end
end
在本地一切正常,但是当我尝试推送到heroku时,我收到了此错误消息。
PG::DatatypeMismatch: ERROR: column "cancel" cannot be cast automatically to type boolean
HINT: You might need to specify "USING cancel::boolean".
: ALTER TABLE "users" ALTER COLUMN "cancel" TYPE boolean
有什么办法解决这个错误吗?
答案 0 :(得分:0)
def change
change_column :users, :cancel, :boolean, default: false
end
应该是:
def
change_column :users, :cancel, 'boolean USING CAST(cancel AS boolean)'
end