我已经设置了一个新的迁移文件:
class ChangeCourseDefaults < ActiveRecord::Migration
def self.up
change_column_null :course_objects, :active, false
change_column_default :course_objects, :active, 0
end
end
我在我的debian服务器上运行它(rails 4.2.1 ruby 2.1)
sudo bundle exec rake db:migrate:up VERSION=20150720095700 RAILS_ENV=test
然后我收到了这个错误:
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'
问题是什么?
答案 0 :(得分:7)
您可以使用 change_column_null
getsockname()
答案 1 :(得分:2)
class ChangeCourseDefaults < ActiveRecord::Migration
def change
change_column_null :course_objects, :active, false, 0
end
end