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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With