ruby-on-rails – 使用迁移更改表列的默认值

我尝试将认列值从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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...