小编Lor*_*ory的帖子

使用迁移更改表列的默认值

我尝试将默认列值从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
'
Run Code Online (Sandbox Code Playgroud)

移民

class ChangeDefaultvalueForHideSeasonSelector < ActiveRecord::Migration 
  def change 
    change_column_default :plussites, :hide_season_selector, from: false, to: true 
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby migration activerecord ruby-on-rails rails-activerecord

9
推荐指数
2
解决办法
3998
查看次数