I've set up a new migration file:
class ChangeCourseDefaults < ActiveRecord::Migration
def self.up
change_column_null :course_objects, :active, false
change_column_default :course_objects, :active, 0
end
end
I run it this way on my debian server (rails 4.2.1 ruby 2.1)
sudo bundle exec rake db:migrate:up VERSION=20150720095700 RAILS_ENV=test
Then I got this error:
Mysql2::Error: Data truncated for column 'active' at row 1: ALTER TABLE `course_objects` CHANGE `active` `active` tinyint(1) NOT NULL/var/www/html/test/xyz/vendor/bundle/ruby/2.1.0/gems/activerecord-4..2.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:299:in `query'
Whats the problem?
You can use change_column_null
class ChangeCourseDefaults < ActiveRecord::Migration
def change
change_column_null :table_name, :column_name, false, 0 # set default as 0
end
end