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

문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top