I mistakenly ran the second to last db migration wrong, but the last migration is fine. Now I want to roll back my second to last migration without reverting the last migration. Please share your knowledge with me and others.
Asked
Active
Viewed 2,720 times
9
-
http://stackoverflow.com/questions/3647685/rails-3-how-to-roll-back-a-migration-file – May 05 '14 at 08:31
4 Answers
7
rake db:migrate:down VERSION=20140804301246
Santhosh
- 26,663
- 9
- 73
- 86
-
i think to rollback command until that migration, and delete that migration then again done all work carefully, i know its bad approach but will it works ? – Awais May 05 '14 at 08:39
-
Thats also a way of doing it :). But you have to be careful if the code is shared with other developers. – Santhosh May 05 '14 at 08:41
2
You can specify your Migration file version number to rollback that Migration.
You can achieve it by either of these
rake db:migrate:down VERSION=your_file_version
OR
rake db:rollback:up VERSION=your_file_version
Pavan
- 32,754
- 7
- 45
- 71
-
i think to rollback command until that migration, and delete that migration then again done all work carefully, i know its bad approach but will it works ? and thanks @pavan – Awais May 05 '14 at 08:40
-
@m_Awais If you have done wrongly only that migration,then you can simply rollback it and do necessary changes correctly and again migrate it. – Pavan May 05 '14 at 08:42
-
2
simple answer i found is
rake db:rollback STEP=X
where X is the number of migration you want to play with(rollback). LIKE
rake db:rollback STEP=3
Awais
- 1,743
- 21
- 24