aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_record_migrations.md
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikac.hu>2015-05-04 16:25:10 -0400
committerPrem Sichanugrist <s@sikac.hu>2015-06-26 16:25:13 -0400
commitf9c841927ac3d1daea2a9cebf08b18e844e5eec5 (patch)
tree890aec3b901aa7bab3adb7b357d7753d09b5bae2 /guides/source/active_record_migrations.md
parenta4128725f5a2c6cbf3e963e2b78ba9382732728a (diff)
downloadrails-f9c841927ac3d1daea2a9cebf08b18e844e5eec5.tar.gz
rails-f9c841927ac3d1daea2a9cebf08b18e844e5eec5.tar.bz2
rails-f9c841927ac3d1daea2a9cebf08b18e844e5eec5.zip
Update guide for new change_column_default syntax
Diffstat (limited to 'guides/source/active_record_migrations.md')
-rw-r--r--guides/source/active_record_migrations.md14
1 files changed, 8 insertions, 6 deletions
diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md
index ad069a112e..0b84001ca5 100644
--- a/guides/source/active_record_migrations.md
+++ b/guides/source/active_record_migrations.md
@@ -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