mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.98k stars 1.19k forks source link

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

Open stanko-tomic opened 7 years ago

stanko-tomic commented 7 years ago

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:inrequire' 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:inrequire' 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:inup' Tasks: TOP => db:migrate (See full trace by running task with --trace)`

RaccoonFive commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

stoplion commented 7 years ago

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 commented 7 years ago

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)

rokumatsumoto commented 5 years ago

Caused by: ArgumentError: Index name 'index_taggings_on_taggable_id_and_taggable_type_and_context' on table 'taggings' does not exist

On *_add_missing_unique_indices.acts_as_taggable_on_engine.rb file

Change this line

remove_index :taggings, [:taggable_id, :taggable_type, :context]

to

if index_exists? :taggings, [:taggable_id, :taggable_type, :context]
      remove_index :taggings, [:taggable_id, :taggable_type, :context]
end

You can reference my gist for migration errors and configuration. https://gist.github.com/rokumatsumoto/e7225334767c68c1859e097442f647a1

ifebrand6 commented 4 years ago

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

thanks