From f9c841927ac3d1daea2a9cebf08b18e844e5eec5 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 4 May 2015 16:25:10 -0400 Subject: Update guide for new change_column_default syntax --- guides/source/active_record_migrations.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'guides/source') 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 -- cgit v1.2.3