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.96k stars 1.19k forks source link

Version 9.0 Relation "index_taggings_on_tag_id" already exists #1071

Open jgrant29 opened 2 years ago

jgrant29 commented 2 years ago

Hi all,

I am running Rails 7.0.0 and Ruby 3.0.3 with gem 'acts-as-taggable-on', '~> 9.0'. With this setup and a new rails app installation, I am receiving the errors noted below on rails db:migrate.

name@iMac alttextproject % rails db:migrate == 20220105163513 ActsAsTaggableOnMigration: migrating ======================== -- create_table(:tags) -> 0.0130s -- create_table(:taggings) -> 0.0085s -- add_index(:taggings, :tag_id) rails aborted! StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR: relation "index_taggings_on_tag_id" already exists /Users/name/here/alttextproject/db/migrate/20220105163513_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:26:in `up'

Caused by: ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "index_taggings_on_tag_id" already exists /Users/name/here/alttextproject/db/migrate/20220105163513_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:26:in `up'

Caused by: PG::DuplicateTable: ERROR: relation "index_taggings_on_tag_id" already exists /Users/name/here/alttextproject/db/migrate/20220105163513_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb:26:in `up'

Thanks! Justin

mu-is-too-short commented 2 years ago

I've been helping Justin try to figure this out over at:

https://stackoverflow.com/q/70599054/479863

The migration has this:

t.references :tag, foreign_key: { to_table: ActsAsTaggableOn.tags_table }
...
add_index ActsAsTaggableOn.taggings_table, :tag_id

But the t.references call creates the index that the add_index is trying to add. But t.references has been adding indexes by default for quite awhile so I'm not sure why the generated migration is broken.

Am I missing something here?

seuros commented 2 years ago

I will delete all the migrations and have only 1 that is skipped by default. It became more difficult to support those legacy migrations at every new release.