我尝试将默认列值从false更改为true.但是当我运行rake db:migrate VERSION = 904984092840298时,我得到了以下错误.
StandardError: An error has occurred,this and all later migrations canceled: PG::InvalidTextRepresentation: ERROR: invalid input Syntax for type boolean: "--- :from: false :to: true " : ALTER TABLE "plussites" ALTER COLUMN "hide_season_selector" SET DEFAULT '--- :from: false :to: true '
移民
class ChangeDefaultvalueForHideSeasonSelector < ActiveRecord::Migration def change change_column_default :plussites,:hide_season_selector,from: false,to: true end end
解决方法
这很奇怪,因为根据文档(
change_column_default
)你的代码应该工作..
作为选项,您可以上下定义:
class ChangeDefaultvalueForHideSeasonSelector < ActiveRecord::Migration def up change_column_default :plussites,true end def down change_column_default :plussites,false end end