diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-09-22 21:22:14 +0900 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2017-02-26 00:23:04 -0700 |
commit | c92757fb68f5a281be0f2ea67e369672e9c4ec6d (patch) | |
tree | 0578c7ffc24acfc43a3161dec82722cbadb51574 /activerecord/test/cases/migration | |
parent | 31d27d5301c79c351c69b91d64e32a64b0f2b0fb (diff) | |
download | rails-c92757fb68f5a281be0f2ea67e369672e9c4ec6d.tar.gz rails-c92757fb68f5a281be0f2ea67e369672e9c4ec6d.tar.bz2 rails-c92757fb68f5a281be0f2ea67e369672e9c4ec6d.zip |
Fix `change_column` to drop default with `null: false`
Currently `change_column` cannot drop default if `null: false` is
specified at the same time. This change fixes the issue.
```ruby
# cannot drop default
change_column "tests", "contributor", :boolean, default: nil, null: false
# we need the following workaround currently
change_column "tests", "contributor", :boolean, null: false
change_column "tests", "contributor", :boolean, default: nil
```
Closes #26582
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r-- | activerecord/test/cases/migration/columns_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/columns_test.rb b/activerecord/test/cases/migration/columns_test.rb index 55c06da411..2329888345 100644 --- a/activerecord/test/cases/migration/columns_test.rb +++ b/activerecord/test/cases/migration/columns_test.rb @@ -225,6 +225,16 @@ module ActiveRecord assert_nil TestModel.new.contributor end + def test_change_column_to_drop_default_with_null_false + add_column "test_models", "contributor", :boolean, default: true, null: false + assert TestModel.new.contributor? + + change_column "test_models", "contributor", :boolean, default: nil, null: false + TestModel.reset_column_information + assert_not TestModel.new.contributor? + assert_nil TestModel.new.contributor + end + def test_change_column_with_new_default add_column "test_models", "administrator", :boolean, default: true assert TestModel.new.administrator? |