Skip to content

Commit

Permalink
Update guide for new change_column_default syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu committed Jun 26, 2015
1 parent b03d047 commit 71221b0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions guides/source/active_record_migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 71221b0

Please sign in to comment.