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

Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top