开发者

Undoing a Migration Error

How do you go about changing column names and types in your rails app? Do you create a new migration to make the changes, 开发者_高级运维or do you rollback, edit your migration file, and then migrate again?

What's the "proper" way to do this in Rails?


It sort of depends on when this happened in your development cycle, If you recently made the change and haven't pushed it out into a public repo, then you indeed might want to do the rollback thing and then edit the migration files and migrate again, just to keep things clean. But if it's a change to a migration that's a few migrations back then you should create a new migration that changes the rows and columns to the "new" old values.


Well, to undo a migration you typically want to roll it back:

bundle exec rake db:rollback

Where VERSION= can also be specified. If you wanted to change it to something entirely new, you would make a new migration. Typically you shouldn't be touching old migrations at all.


Rails gives you the choice of creating a migration and changing it a various of ways. So there is no "ruby developers" technique of choice.

However, every time you create a migration, a file is created, and it represents the history of your development. There are a lot of cases that a simpler file should be uselfull, like a code that other ruby beginners would have to look at and modify. On other cases may be necessary to an advanced developer understand changes and improvements made on the code, specially if it is a code running for a long time (some years maybe).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜