Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

ActiveRecord::PendingMigrationError #15

Closed
flanaganm87 opened this issue Jan 28, 2014 · 9 comments
Closed

ActiveRecord::PendingMigrationError #15

flanaganm87 opened this issue Jan 28, 2014 · 9 comments

Comments

@flanaganm87
Copy link

I CD to nku-rails directory and wanted to ensure my new box was working correctly, so I entered rails server, the server started up successfully and when I went to preview (assignment 1) I now get the following error.
I did some research and found that I am supposed to run the command that it tells me ( bin/rake db:migrate RAILS_ENV=development ), if that does not work ( which it failed ) with the following console message:

CreateComments: migrating =================================================
-- create_table(:comments)
-> 0.0116s
-- add_index(:comments, :post_id)
rake aborted!

I then read that I need to do a server restart, so I tried to reboot the server but I do not have root access to this box. Can a root please restart it for me if that's the case?

rubyerror

@jaimerump
Copy link

By server restart, does it mean the entire box or just the rails server? If just the rails server, all you have to do is hit control-c in the terminal you originally started it in. It might just be that rails can't run the migration while the server is running for whatever reason.

@cdmwebs
Copy link

cdmwebs commented Jan 29, 2014

@flanaganm87 you copied and pasted most of the output, but the lines just after you stopped would have been the most helpful.

Also, @jaimerump is correct about restarting the Rails server. You don't need to in this particular instance, though, as Rails will continue once the migration is successful.

@flanaganm87
Copy link
Author

I did not have the server running while using the migrate command, but here is the rest of the error

$ bin/rake db:migrate RAILS_ENV=development
== CreateComments: migrating =================================================
-- create_table(:comments)
-> 0.0068s
-- add_index(:comments, :post_id)
rake aborted!
An error has occurred, this and all later migrations canceled:

Index name 'index_comments_on_post_id' on table 'comments' already exists/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:815:in add_index_option s' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:521:inadd_index'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:625:in block in method_missing' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:inblock in say_with_time'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in say_with_time' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:617:inmethod_missing'
/home/action/nku-rails/db/migrate/20140123223406_create_comments.rb:10:in change' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:571:inexec_migration'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:555:in block (2 levels) in migrate' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:554:inblock in migrate'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in with_connection' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:553:inmigrate'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:709:in migrate' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:959:inblock in execute_migration_in_transaction'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in block in ddl_transaction' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:inblock in transaction'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in within_new_transaction' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:intransaction'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in transaction' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:inddl_transaction'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:958:in execute_migration_in_transaction' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:920:inblock in migrate'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in each' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:inmigrate'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:764:in up' /home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/migration.rb:742:inmigrate'
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate

@cdmwebs
Copy link

cdmwebs commented Jan 29, 2014

@flanaganm87 the important line in there is: Index name 'index_comments_on_post_id' on table 'comments' already exists. It's tough to figure out how this happened without access to the db, but you could try dropping and re-creating the database:

  1. rake db:drop
  2. rake db:create
  3. rake db:migrate

See if that gets you past the error.

@flanaganm87
Copy link
Author

@cdmwebs , I ran the the three mentioned commands, and I ensured that the development.sqlite3 file was removed, and I am still getting the same error as above.

@agilous
Copy link
Member

agilous commented Jan 29, 2014

Any chance you are adding the index twice in separate migrations?

A way to test it would be to remove the one added in: db/migrate/20140123223406_create_comments.rb. Then see if the index is still defined in: db/schema.rb. Just search db/schema.rb for "index_comments_on_post_id" after you repeat the steps @cdmwebs gave you.

@rockwood
Copy link
Contributor

Hey @flanaganm87. I just took a look at your migrations and the problem is that you're trying to add multiple indexes.

def change
    create_table :comments do |t|
      t.string :commenter
      t.text :body
      t.references :post, index: true

      t.timestamps
    end
    add_index :comments, :post_id
  end

Removing either the add_index line or the index: true should resolve the issue.

@flanaganm87
Copy link
Author

I removed the index: true and it worked, I don't understand how this happened though, I don't recall editing this file, and it clearly worked for assignment#1. Thanks though!

@Spartan-196
Copy link

@flanaganm87 I had this same in class issue after migrating to the new box @rockwood helped me resolve it then.
Though not super clearly explained by the error message it gives after looking into it appears to be as stated above an issue with multiple indexes. Primarily in our case it seem to be cause by the fact we moved everything including already raked databases over to the new box and and reset up rails. It seems to be unable to handle that situation effectively.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants