Coder Social home page Coder Social logo

Comments (9)

jaimerump avatar jaimerump commented on September 1, 2024

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.

from nku.

cdmwebs avatar cdmwebs commented on September 1, 2024

@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.

from nku.

flanaganm87 avatar flanaganm87 commented on September 1, 2024

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

from nku.

cdmwebs avatar cdmwebs commented on September 1, 2024

@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.

from nku.

flanaganm87 avatar flanaganm87 commented on September 1, 2024

@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.

from nku.

agilous avatar agilous commented on September 1, 2024

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.

from nku.

rockwood avatar rockwood commented on September 1, 2024

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.

from nku.

flanaganm87 avatar flanaganm87 commented on September 1, 2024

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!

from nku.

Spartan-196 avatar Spartan-196 commented on September 1, 2024

@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.

from nku.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.