drewwyatt
drewwyatt

Reputation: 6027

Destroying a reference to a deleted migration

Well, I made a huge mistake and deleted a couple of migrations locally (now I know better). This is becoming a problem because now when I attempt to deploy to heroku, I am getting the following error:

Running `rake db:migrate` attached to terminal... up, run.3430
rake aborted!
Multiple migrations have the name CreateScores
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:978:in `validate'

This surprised me at first, because I only have one migration named "create scores" - but then I noticed this:

Drews-MacBook-Pro:quiz drewwyatt$ rake db:migrate:status

database: /Users/drewwyatt/Sites/Ruby/Rails/quiz/db/development.sqlite3

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20130828212225  Create answers
   up     20130828212306  Create questions
   up     20130829210727  Create quizzes
   up     20130829211302  Remove quiz id from question
   up     20130829212349  Create assignments
   up     20130829234338  Create employees
   up     20130829234541  Add role and active to employee
   up     20130830032801  ********** NO FILE **********
   up     20130902183412  ********** NO FILE **********
   up     20130902183530  Create scores
   up     20130902230036  Add indexes to score
   up     20130904210011  Create positions
   up     20130904212007  Add position to employee
   up     20130905161805  Create quiz assignments

My assumption is that one of the deleted migrations was also named "create scores". So my question is, how can I get rid of the 2 deleted migrations?

Upvotes: 0

Views: 173

Answers (2)

Rajesh Omanakuttan
Rajesh Omanakuttan

Reputation: 6918

Roll back to a version which is just above the migration for which you are getting error. You can do that as given below.

rake db:migrate:down VERSION=20130829234541

Then delete any reference related to the error if there exists in you root/db/migrate folder.

Then run migrations again. It will be fine.

Upvotes: 1

Sabyasachi Ghosh
Sabyasachi Ghosh

Reputation: 2785

For a quick solution, you can migrate each version of the migration file one by one rather than all the migration at once like

rake db:migrate:up VERSION=version_of_the file

Please check this link: Run a single migration file

Upvotes: 2

Related Questions