From 4b87780abc2cc1ae0169f5ca14d7632bd6dc30ec Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Tue, 24 Mar 2015 09:06:28 -0300 Subject: Documenting remove_column as a reversible migration method [ci skip] --- guides/source/active_record_migrations.md | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'guides') diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md index a2b7b7a818..de8bbc4174 100644 --- a/guides/source/active_record_migrations.md +++ b/guides/source/active_record_migrations.md @@ -539,6 +539,14 @@ definitions: `change_table` is also reversible, as long as the block does not call `change`, `change_default` or `remove`. +`remove_column` is reversible if you supply the column type as the third +argument. Provide the original column options too, otherwise Rails can't +recreate the column exactly when rolling back: + +```ruby +remove_column :posts, :slug, :string, null: false, default: '', index: true +``` + If you're going to need to use any other methods, you should use `reversible` or write the `up` and `down` methods instead of using the `change` method. -- cgit v1.2.3