views:

217

answers:

2

i have a bug in a "self.drop" in a migration such that I cannot roll back past that migration. how can i start from scratch and build up from migration 001? also, is there a way to do this without losing my data (it's just testing, but still...)

+1  A: 
rake db:drop
rake db:create
rake db:migrate

It will reset your database and run all migrations. If you don't want to lose your data you can save it using plugin yaml_db:

rake db:data:dump  # stores all data in db/data.yml
...
rake db:data:load  # loads db/data.yml to database

If you have an error in a migration you can edit it and then try to rollback.

klew
+1  A: 

You can comment all statements in self.down migration and rollback to previous db version.

Then apply changes by hand using a gui/web db client to match db schema before migration.

After you will be able to run migration again and your data will not be lost.

VitalieL