Felix Felix - 6 months ago 18
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"
end


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
end


same error

What is the problem in this case?

Answer

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