Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 generate migration - no up or down method

Just learning rails, am on to migrations and it all started off pretty logically until I hit something odd going on in the code;

rails generate migration AddRegionToSupplier

The above produces a migration file with only a "def change" method in it.

I googled this and found that this is exactly what is supposed to happen;

http://guides.rubyonrails.org/migrations.html

I would have expected it to generate a "def up" and "def down" method, so that the migration could be rolled back. Have I done something wrong in the generation or am I missing something obvious?

like image 311
Mikey Hogarth Avatar asked Sep 29 '11 16:09

Mikey Hogarth


1 Answers

From the link you pasted:

Rails 3.1 makes migrations smarter by providing a new change method. This method is preferred for writing constructive migrations (adding columns or tables). The migration knows how to migrate your database and reverse it when the migration is rolled back without the need to write a separate down method.

So it looks like you don't have to worry about having a def self.down as Rails is now smart enough to know how to roll it back.

like image 91
rickmzp Avatar answered Sep 27 '22 23:09

rickmzp