knocked loose
knocked loose

Reputation: 3304

Pending Migration Error | Cannot Remove Dupe Migrations

I am trying to run a rails server and am coming across this error:

Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development

The DB in question is currently empty so no worries of losing data. When I run the code:

bundle exec rake db:migrate

RAILS_ENV=development rake db:migrate

rake db:migrate

I am returned the error:

rake aborted!
ActiveRecord::DuplicateMigrationNameError: 

Multiple migrations have the name CreatePosts


Tasks: TOP => db:migrate
(See full trace by running task with --trace)

When running the server, this is returned to my terminal:

Started GET "/" for ::1 at 2015-09-22 11:30:34 -0400

ActiveRecord::PendingMigrationError (

Migrations are pending. To resolve this issue, run:

bin/rake db:migrate RAILS_ENV=development

):

And finally, running rake db:migrate:status returns:

Schema migrations table does not exist yet.

What could possibly be going on? Any help is greatly appreciated!


Output of migrate:status after bin/rake command

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20150922142819  Devise create users
   up     20150922143253  Create posts
  down    20150922143414  Create posts
  down    20150922145906  Acts as votable migration
  down    20150922150209  Create comments
  down    20150922151035  Acts as follower migration

Upvotes: 2

Views: 818

Answers (2)

sjagr
sjagr

Reputation: 16502

You must create the database schema/structure before you run migrations. db:schema:load will do this for you:

bin/rake db:schema:load

As for the error "Multiple migrations have the name CreatePosts" - it's as it says. Look in the contents your db/migrate folder for two files that have the same name class CreatePosts within the files - they should be named differently, or the second one should be removed if they are duplicates.

Upvotes: 2

tadman
tadman

Reputation: 211580

It seems like you have more than one migration with the same name. This is not allowed. If your database is empty, no tables, the best plan is to rename the second one so they don't conflict any more.

Obviously the filenames are unique, but each migration file defines a class, and these classes must be unique as well, plus should match the filename.

Having 201509201949343_create_posts and 201509220293910_create_posts would be a typical conflict here.

You may want to investigate how this came to pass, as having your development schema diverge from the production one is generally a bad idea. Once you resolve the conflict locally, try and update the schema tracking table on production accordingly.

Upvotes: 0

Related Questions