I have a migration named “20120311145341_create_resource1s.rb”. I accidently deleted that table in database. I ran “rake db:migrate” but the it doesn’t restore that table. How to restore it?
I have a migration named 20120311145341_create_resource1s.rb. I accidently deleted that table in database. I
Share
You can’t run
db:migrateagain because I think you’re already on the latest migration.a) If the migration you’re trying to recreate is the latest one, you can do the following to rollback it, and then run it again.
rake db:rollbackrake db:migrateb) If it’s not the latest migration, you need to list the files in
db/migratedirectory, annotate the version of the previous migration to 20120311145341_create_resource1s.rb and then run:rake db:migrate VERSION=20120309101821(change the version to right one for you)rake db:migratePlease note, if you get an error like this one
Mysql2::Error: Unknown table 'xxx': DROP TABLE 'xxx'you can workaround it making sure you check for the table existence in the migration down method:I hope it helps.