数据库列上的 Heroku 错误
Heroku error on DB column
我有一个 rails 应用程序,其中有一列名为 cancel
我为此进行了 2 次迁移,因为我将其从 string
更改为 boolean
此迁移首先运行:
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
知道如何克服这个错误吗?
def change
change_column :users, :cancel, :boolean, default: false
end
应该改为:
def
change_column :users, :cancel, 'boolean USING CAST(cancel AS boolean)'
end
我有一个 rails 应用程序,其中有一列名为 cancel
我为此进行了 2 次迁移,因为我将其从 string
更改为 boolean
此迁移首先运行:
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
知道如何克服这个错误吗?
def change
change_column :users, :cancel, :boolean, default: false
end
应该改为:
def
change_column :users, :cancel, 'boolean USING CAST(cancel AS boolean)'
end