Undoing a migration....
Bill Thayer
9 posts
|
While attempting to move the payment options to a database table I get migration errors. I’ve been trying to revert back using >rake db:migrate VERSION=6 but I get the same errors. Basically it says that the table ‘payment_types’ exists but I’m under the impression that >rake db:migrate VERSION=6 should remove that table. This is a partial copy from my cmd window of my last attempt. C:\InstantRails-2.0-win\rails_apps\depot>ruby script/generate scaffold payment_type label:string value:string
C:\InstantRails-2.0-win\rails_apps\depot>rake db:migrate (See full trace by running task with—trace) |
James West
70 posts
|
It seems to me as though your version 6 migration is the migration that created the tables. If you want to remove the table then migrate to the version before that. I tend to use the roll back migration rather than a specific version number but I guess it all depends on what you actually want to achieve. Anyway I guess you should look at the migration files that you have and migrate to the one prior to the version 6. I have not explored the migrate down options yet and this may well prove to be another alternative for achieving the same thing. Hope this helps James |
Steve Ross
3 posts
|
You need to make sure that the migration has def self.down drop_table :payment_types end |
Bill Thayer
9 posts
|
Thank you James & Steve. My bad. After going through my command history I see I had the syntax wrong. I typed: depot>rake db:migrate version = 6 it should have been depot>rake db:migrate VERSION=6 I guess the caps and no spaces matter for the argument VERSION=6. My next post will be the output from my console after running >rake db:migrate—trace Here is my 007_create_payment_types.rb file: |
Bill Thayer
9 posts
|
Here’s my cmd window output: |
Bill Thayer
9 posts
|
I even tried going back to VERSION=5 but got the same result: |
Steve Ross
3 posts
|
The version that creates :payment_types should also contain the drop definition migrate to a previous version (ie: if 5 has the create payment_types then migrate back to 4 while making sure that v5 has drop :payment_types defined) then migrate back to 6 or whatever one you want. |
Steve Ross
3 posts
|
make sure when you migrate to VERSION=5 that you see the drop :payment_types executing. If it isn’t then that is why the error is being thrown… the table already exists. You might have to drop the table manually for rails to sync back up with which version you are using of the app and what version the db is on. |
David Johnson
1 post
|
I have a feeling you are sitting a bit in limbo in the database, where your schema is at 6 but at some point previously the payment_types table was created. You never are getting to version 7 to have it actually drop the table when you revert. You have a couple options, bring up your database in the console and manually drop the table. You could reset the database with rake although you will lose any data and then rebuild your entire database from scratch through the migrations. Add the drop table to your 006 migration temporarily and then remove once the table is deleted. |
9 posts, 4 voices
