ruby-on-rails – 使用迁移更改表列的默认值
发布时间:2020-12-17 03:07:39 所属栏目:百科 来源:网络整理
导读:我尝试将默认列值从false更改为true.但是当我运行rake db:migrate VERSION = 904984092840298时,我得到了以下错误. StandardError: An error has occurred,this and all later migrations canceled:PG::InvalidTextRepresentation: ERROR: invalid input sy
我尝试将默认列值从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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |