Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake db:rollback not working?

I'm writing my first Rails app. I've run a few rails generate model ... and rake db:migrate commands, but I now want to change my data model and so need to undo a few migrations.

The docs say I can undo a migration with rake db:rollback, but this isn't working. When I run this in the console the computer thinks for a few seconds but doesn't make any changes to db/migrate/ or db/migrate/schema.rb. No output is printed to the console.

Is this behavior correct? Shouldn't db:rollback be changing my schema? If so, can anyone think why it might not be working?

I'm on Rails v. 3.2.6.

EDIT

At the moment rake db:migrate:status gives

database: db/development.sqlite3   Status   Migration ID    Migration Name --------------------------------------------------    up     20120617191211  Create irs    up     20120701154357  Create paths    up     20120701154421  Create nodes    up     20120702151447  ********** NO FILE **********   down    20120702155140  Create venues   down    20120703233833  Remove path from venues 
like image 271
dB' Avatar asked Jul 03 '12 23:07

dB'


People also ask

How do I rollback a specific migration?

i found these steps most useful. To check for status, run rails db:migrate:status . Then you'll have a good view of the migrations you want to remove. Then, run rails db:rollback to revert the changes one by one.

How do I rollback a migration in Rails?

You must rollback the migration (for example with bin/rails db:rollback ), edit your migration, and then run bin/rails db:migrate to run the corrected version.

What does Rails db Reset do?

db:reset: Resets your database using your migrations for the current environment. It does this by running the db:drop , db:create , db:migrate tasks. db:rollback: Rolls the schema back to the previous version, undoing the migration that you just ran. If you want to undo previous n migrations, pass STEP=n to this task.


1 Answers

Solution (see my comment): run

rake db:migrate:status 

and correct problems you find there. In this case (per @MarkThomas' followup), you might want to check all files you need are in place.

like image 74
Peter Avatar answered Sep 21 '22 09:09

Peter