method
change_column_default
v4.2.1 -
Show latest stable
-
4 notes -
Class: ActiveRecord::ConnectionAdapters::SchemaStatements
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (0)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-3)
- 3.1.0 (-26)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (12)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (38)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- 7.2.3 (0)
- 8.0.0 (0)
- 8.1.1 (0)
- What's this?
change_column_default(table_name, column_name, default)
public
Sets a new default value for a column:
change_column_default(:suppliers, :qualification, 'new') change_column_default(:accounts, :authorized, 1)
Setting the default to nil effectively drops the default:
change_column_default(:users, :email, nil)
Register or
log in
to add new notes.
mutru -
October 10, 2008
Vidmantas -
July 30, 2009
Vidmantas -
October 10, 2008 - (v2.1.0)
meritize -
July 20, 2014
8 thanks
Implemented in database adapters
These methods are not implemented in the abstract classes. Instead, all database adapters implement these separately, if the feature is supported.
2 thanks
How to set default value to NULL
To set default value to NULL you can use change_column method instead, for example:
change_column :suppliers, :qualification, :string, :default => nil
Just make sure you don’t change data type accidentally ;-)
1 thank
Not implented yet
According to this method’s source, change_column_default is not implemented as well as change_column
0 thanks
change_column did the trick for me
Use change_column, and make sure to specify the datatype:
class ChangeUsers < ActiveRecord::Migration def up change_column :users, :is_vote_reminder, :boolean, :default => true end end

