Felix Felix - 1 year ago 105
Ruby Question

rails migration error default value wrong

I've got an migration error in rails.

def self.up
change_column_default :course_objects, :active, :default => "0"

error is

Mysql2::Error: Invalid default value for 'active': ALTER TABLE `course_objects` CHANGE `active` `active` tinyint(1) DEFAULT '---\n:default: \'0\'\n'

also tried this:

def self.up
change_column_default :course_objects, :active, :default => 0

same error

What is the problem in this case?

Answer Source

change_column_default takes the default as the third parameter, not a hash including a :default key. You want:

change_column_default :course_objects, :active, 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download