Skip to content

change_column_null does not reverse automatically #13576

Closed
derekprior opened this Issue Jan 2, 2014 · 0 comments

1 participant

@derekprior

When present in the change method of a migration, change_column_null does not reverse. The rollback will succeed without error but the schema is not changed.

def change
  change_column_null :orders, :product_id, false
end

When migrated up and then down will output:

==  AddNotNullToOrderForeignKeys: migrating ==============================
-- change_column_null(:orders, :product_id, false)
   -> 0.0004s
==  AddNotNullToOrderForeignKeys: migrated (0.0005s) =====================

==  AddNotNullToOrderForeignKeys: reverting ==============================
==  AddNotNullToOrderForeignKeys: reverted (0.0000s) =====================

Inspection of the schema after rollback confirms that the column is still marked as not null.

I have verified this on Rails 4.0.2 with the postgres adapter and suspect it will be reproducible for any adter that uses CommandRecorder for reverts.

@prathamesh-sonpatki prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this issue Jan 7, 2014
@prathamesh-sonpatki prathamesh-sonpatki Negate null argument while reverting change_column_null_migration
  null argument should be negated based on the direction of migration
  while reverting change_column_null_migration so that NOT NULL constraint is set up or
  dropped accordingly.

  Fixes #13576
117c319
@prathamesh-sonpatki prathamesh-sonpatki added a commit to prathamesh-sonpatki/rails that referenced this issue Jan 7, 2014
@prathamesh-sonpatki prathamesh-sonpatki Negate null argument while reverting change_column_null_migration
  null argument should be negated based on the direction of migration
  while reverting change_column_null_migration so that NOT NULL constraint is set up or
  dropped accordingly.

  Fixes #13576
4b5e40f
@senny senny closed this in 724509a Jan 8, 2014
@tenderlove tenderlove added a commit that referenced this issue Jan 10, 2014
@tenderlove tenderlove Merge branch 'master' into laurocaetano-fix_send_file
* master: (536 commits)
  doc, API example on how to use `Model#exists?` with multiple IDs. [ci skip]
  Restore DATABASE_URL even if it's nil in connection_handler test
  [ci skip] - error_messages_for has been deprecated since 2.3.8 - lets reduce any confusion for users
  Ensure Active Record connection consistency
  Revert "ask the fixture set for the sql statements"
  Check `respond_to` before delegation due to: ruby/ruby@d781caa
  Adding Hash#compact and Hash#compact! methods
  MySQL version 4.1 was EOL on December 31, 2009 We should at least recommend modern versions of MySQL to users.
  clear cache on body close so that cache remains during rendering
  add a more restricted codepath for templates fixes #13390
  refactor generator tests to use block form of Tempfile
  Fix typo [ci skip]
  Move finish_template as the last public method in the generator
  Minor typos fix [ci skip]
  make `change_column_null` reversible. Closes #13576.
  create/drop test and development databases only if RAILS_ENV is nil
  Revert "Speedup String#to"
  typo fix in test name. [ci skip].
  `core_ext/string/access.rb` test what we are documenting.
  Fix typo in image_tag documentation
  ...

Conflicts:
	actionpack/CHANGELOG.md
caa981d
@tenderlove tenderlove added a commit that referenced this issue Jan 17, 2014
@tenderlove tenderlove Merge branch 'master' into set_binds
* master: (2794 commits)
  doc, API example on how to use `Model#exists?` with multiple IDs. [ci skip]
  Restore DATABASE_URL even if it's nil in connection_handler test
  [ci skip] - error_messages_for has been deprecated since 2.3.8 - lets reduce any confusion for users
  Ensure Active Record connection consistency
  Revert "ask the fixture set for the sql statements"
  Check `respond_to` before delegation due to: ruby/ruby@d781caa
  Adding Hash#compact and Hash#compact! methods
  MySQL version 4.1 was EOL on December 31, 2009 We should at least recommend modern versions of MySQL to users.
  clear cache on body close so that cache remains during rendering
  add a more restricted codepath for templates fixes #13390
  refactor generator tests to use block form of Tempfile
  Fix typo [ci skip]
  Move finish_template as the last public method in the generator
  Minor typos fix [ci skip]
  make `change_column_null` reversible. Closes #13576.
  create/drop test and development databases only if RAILS_ENV is nil
  Revert "Speedup String#to"
  typo fix in test name. [ci skip].
  `core_ext/string/access.rb` test what we are documenting.
  Fix typo in image_tag documentation
  ...

Conflicts:
	activerecord/lib/active_record/associations/join_dependency/join_association.rb
	activerecord/lib/active_record/relation/query_methods.rb
11e8bad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.