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 mis开发者_开发百科sing something obvious?
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.
精彩评论