Does the latest version of Rails require my db migration files to have “down” (undo) commands for the db?

StackOverflow https://stackoverflow.com/questions/10630555

Domanda

Because it sure doesn't seem like it. When I generate a model and check out it's db migration file (I'm a bit of noob so forgive me for any ignorance), there is no "down" code which has been automatically generated. Is this because the newest rails versions have figured out how to handle this for me automatically?

È stato utile?

Soluzione

The latest versions of rails support a method called change; if Rails can figure out how to reverse the migration simply by the contents of this migration--and it usually can if you use just the built-in migration methods--then you don't need to define a down method.

If you need to do something custom, or Rails can't figure out how to reverse the migration, you'll need to write up and down methods instead of change.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top