Update guide for new change_column_default syntax

This commit is contained in:
Prem Sichanugrist 2015-05-04 16:25:10 -04:00
parent a4128725f5
commit f9c841927a

@ -423,21 +423,23 @@ change_column :products, :part_number, :text
```
This changes the column `part_number` on products table to be a `:text` field.
Note that `change_column` command is irreversible.
Besides `change_column`, the `change_column_null` and `change_column_default`
methods are used specifically to change a not null constraint and default values of a
column.
methods are used specifically to change a not null constraint and default
values of a column.
```ruby
change_column_null :products, :name, false
change_column_default :products, :approved, false
change_column_default :products, :approved, from: true, to: false
```
This sets `:name` field on products to a `NOT NULL` column and the default
value of the `:approved` field to false.
value of the `:approved` field from true to false.
TIP: Unlike `change_column` (and `change_column_default`), `change_column_null`
is reversible.
Note: You could also write the above `change_column_default` migration as
`change_column_default :products, :approved, false`, but unlike the previous
example, this would make your migration irreversible.
### Column Modifiers