New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index name 'index_taggings_on_tag_id' on table 'taggings' already exists #845

Open
cayber opened this Issue Jul 8, 2017 · 5 comments

Comments

Projects
None yet
6 participants
@cayber

cayber commented Jul 8, 2017

When i try running rake db:migrate it outputs this
`C:\Sites\novosti>rails db:migrate
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:2:in <top (required)>' bin/rails:4:in require'
bin/rails:4:in `

'
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]
C:/Sites/novosti/db/migrate/20170708123900_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:2:in <top (required)>' bin/rails:4:in require'
bin/rails:4:in <main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)

I fixed it buy putting [5.0] on the end of the generated acts_as_taggable_on_migration.acts_as_taggable_on_engine

But then i got this error

`C:\Sites\novosti>rake db:migrate
== 20170708144217 ActsAsTaggableOnMigration: migrating ========================
-- adapter_name()
-> 0.0000s
-- adapter_name()
-> 0.0000s
-- create_table(:tags, {:id=>:integer})
-> 0.0029s
-- adapter_name()
-> 0.0000s
-- adapter_name()
-> 0.0000s
-- create_table(:taggings, {:id=>:integer})
-> 0.0032s
-- add_index(:taggings, :tag_id)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Index name 'index_taggings_on_tag_id' on table 'taggings' already exists
C:/Sites/novosti/db/migrate/20170708144217_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:23:in up' ArgumentError: Index name 'index_taggings_on_tag_id' on table 'taggings' already exists C:/Sites/novosti/db/migrate/20170708144217_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:23:in up'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)`

@RaccoonFive

This comment has been minimized.

RaccoonFive commented Jul 20, 2017

I had the same problem when I was putting [5.0] after the migration name so I tried with [4.2] instead and it worked!

@alessandroasac

This comment has been minimized.

alessandroasac commented Jul 24, 2017

Just remove the following line from *_act_as_tatggable_on_migration.acts_as_taggable_on_engine.rb:

add_index :taggings, :tag_id

Cause:
add_index :taggings, :tag_id already add the index.

@liangchaob

This comment has been minimized.

liangchaob commented Aug 6, 2017

Thanks @RaccoonFive ,I have the same problem, use [4.2] instead works!

@stoplion

This comment has been minimized.

stoplion commented Aug 19, 2017

Added a unless index_exists?(:taggings, :tag_id) postifx to add_index :taggings, :tag_id
line 23 on *_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb to fix.

@ltfschoen

This comment has been minimized.

ltfschoen commented Nov 5, 2017

Using Rails 5.1.3, after generating migrations with rails acts_as_taggable_on_engine:install:migrations, I then tried to migrate them with bundle exec rails db:drop db:create db:migrate but it gave me error

Caused by:
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

  class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]

So I fixed that error by just appending the missing [5.1] to each migration (i.e. class ActsAsTaggableOnMigration < ActiveRecord::Migration[5.1])

Then when I ran bundle exec rails db:drop db:create db:migrate again it gave me error:

== 20171104224110 ActsAsTaggableOnMigration: migrating ========================
-- create_table(:tags)
   -> 0.0049s
-- create_table(:taggings)
   -> 0.0191s
-- add_index(:taggings, :tag_id)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Index name 'index_taggings_on_tag_id' on table 'taggings' already exists

I fixed this by using advice from @stoplion by modifying db/migrate/20171104224110_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb by
appending unless index_exists?(:taggings, :tag_id) to the line add_index :taggings, :tag_id so it became add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment