The Rails guides to active record migrations says that you can do
change_column_default :products, :approved, from: true, to: false
I\'ve got a
from
and to
was added in Rails 5+The guide linked to in the question is for Edge Rails, not for a released version of Rails.
Reversible syntax for change_column_default
is the result of pull request 20018. The pull request also updated the Rails guides for Edge Rails.
From activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
:
- def change_column_default(table_name, column_name, default)
+ # Passing a hash containing +:from+ and +:to+ will make this change
+ # reversible in migration:
+ #
+ # change_column_default(:posts, :state, from: nil, to: "draft")
+ #
+ def change_column_default(table_name, column_name, default_or_changes)
The pull request was made June 27, 2015, which is more recent than any version of Rails released as of August 1, 2015.
The documentation for migration for Rails 4.2.3 reflects the fact that reversible syntax is not yet available:
change_column_default :products, :approved, false