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 3,157 times
10
-
http://stackoverflow.com/questions/3647685/rails-3-how-to-roll-back-a-migration-file – May 05 '14 at 08:31
4 Answers
8
rake db:migrate:down VERSION=20140804301246

Santhosh
- 28,097
- 9
- 82
- 87
-
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
- 33,316
- 7
- 50
- 76
-
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,803
- 22
- 26