Theo
Theo

Reputation: 51

Delete migration file with duplicate migration name

I’m working in a rails application in c9. I created a migration entering the command in the terminal, (rails generate migration CreateContacts), it generated a migration file (20160928153918 create_contacts.rb). The application was pushed to Heroku, but I noticed certain files including this migration file, did not reflect in the File Directory when I proceeded with my Rails application project. I’m still a student learning web development, I proceeded to create a new migration file (20161109062718 create_contacts.rb) not knowing what happened to the previous migration file. Ever since am I getting this error message: "ActiveRecord::PendingMigrationError Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development". When I enter this command in the terminal, ($ bin/rake db:migrate RAILS_ENV=development )I get the following error message: "ActiveRecord::DuplicateMigrationNameError: Multiple migrations have the name CreateContacts". When I enter the following command, $ rake db:migrate:status, it indicates the following:

Status Migration ID Migration Name

up 20160928153918 Create contacts down 20161109062718 Create contacts

Both migrations have the same migration name, create contacts, and this is now obviously the reason for the error messages. To solve the problem, will deleting this newest 20161109062718 create_contacts.rb file in the File Directory be a solution to this duplicate migration name, create contacts? I do not want to delete my first migration file, 20160928153918 create_contacts.rb. If the newest file can simply be deleted, what other commands is associated with this action? Do find attached pics of my problem.

I require expert advice on this point as I am still learning the trade Duplicate migration names

[Pending migration 1

Upvotes: 2

Views: 2382

Answers (1)

Theo
Theo

Reputation: 51

This problem was solved by entering: rake db:migrate:status in the console, The migrations were listed, the actual duplicate migration was deleted in the File Directory, thereafter the following was entered in the console, git status; git add .; git commit -m "Deleted migration" and the problem was solved.

Upvotes: 2

Related Questions