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?
change_column_null :course_objects, :active, falseruns it will check for all values and confirm there should not be any null. and here it crashes. but i guess the answer pasted below will solve your problem.