My situation is the following: I was working on my rails app and decided to create a model so I used the command rails generate model Micropost content:string user_id:integer
. After that, the migration file db/migrate/[timestamp]_create_microposts.rb
was created, and started to play with it adding some columns and indexes. Finally I migrated using rake db:migrate
.
The problem comes when I decided that I needed to go back and delete the model Micropost, so I made the mistake to go directly to delete the model using rails destroy model Micropost
and then I realized that I needed to make a rollback to the database. But it doesn't work anymore because the migration file was deleted when I hitted rails destroy.
Is there any "nice" or "correct" way to go back to the initial database version, the one before I created the model Micropost?
My rake db:migrate:state
is the following:
Status Migration ID Migration Name
--------------------------------------------------
up 20140101222024 Create users
up 20140102220824 Add index to users email
up 20140102222352 Add password digest to users
up 20140105055539 Add remember token to users
up 20140108013447 Add admin to users
up 20140109211729 ********** NO FILE **********
By the way, solutions like creating a "dummy" migration file (as i found here) with the same name id is NOT a solution, it will only skip the rollback (the table Microposts will still exist). Also, I found this question useful, but is not the same problem, because I destroyed the model before rolling back (or migrating down to a previous version).
Bottom Line:
Is there a way to perform this rollback? or is just impossible because the migration file was deleted?