Skip to content
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

Mysql2::Error: Cannot drop index 'index_taggings_on_tag_id': needed in a foreign key constraint: DROP INDEX index_taggings_on_tag_id ON taggings #978

Closed
denmarkmeralpis opened this issue Nov 28, 2019 · 11 comments

Comments

@denmarkmeralpis
Copy link

I got an error while running rails db:migrate. I'm using rails 5.2 and ruby 2.5.3

Here's the log

rails db:migrate
== 20191128014312 ActsAsTaggableOnMigration: migrating ========================
-- create_table(:tags)
   -> 0.0781s
-- create_table(:taggings)
   -> 0.0132s
-- index_exists?(:taggings, :tag_id)
   -> 0.0008s
-- add_index(:taggings, [:taggable_id, :taggable_type, :context], {:name=>"taggings_taggable_context_idx"})
   -> 0.0100s
== 20191128014312 ActsAsTaggableOnMigration: migrated (0.1023s) ===============

== 20191128014313 AddMissingUniqueIndices: migrating ==========================
-- add_index(:tags, :name, {:unique=>true})
   -> 0.0124s
-- index_exists?(:taggings, :tag_id)
   -> 0.0004s
-- remove_index(:taggings, :tag_id)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Cannot drop index 'index_taggings_on_tag_id': needed in a foreign key constraint: DROP INDEX `index_taggings_on_tag_id` ON `taggings`
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `_query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `block in query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `handle_interrupt'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:187:in `block (2 levels) in execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:186:in `block in execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:185:in `execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/mysql/database_statements.rb:28:in `execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:788:in `remove_index'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:871:in `block in method_missing'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:840:in `block in say_with_time'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:840:in `say_with_time'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:860:in `method_missing'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:604:in `method_missing'
/Users/denmark/Core/ProjectX/db/migrate/20191128014313_add_missing_unique_indices.acts_as_taggable_on_engine.rb:11:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:777:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:817:in `exec_migration'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:798:in `block (2 levels) in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:797:in `block in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:796:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:977:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1292:in `block in execute_migration_in_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1345:in `ddl_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1291:in `execute_migration_in_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1263:in `block in migrate_without_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `each'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `migrate_without_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `block in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1363:in `with_advisory_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1036:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1011:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:172:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bugsnag-6.11.1/lib/bugsnag/integrations/rake.rb:18:in `execute_with_bugsnag'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/Users/denmark/Core/ProjectX/bin/rails:9:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/denmark/Core/ProjectX/bin/spring:15:in `require'
/Users/denmark/Core/ProjectX/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Cannot drop index 'index_taggings_on_tag_id': needed in a foreign key constraint: DROP INDEX `index_taggings_on_tag_id` ON `taggings`
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `_query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `block in query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `handle_interrupt'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:187:in `block (2 levels) in execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:186:in `block in execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:185:in `execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/mysql/database_statements.rb:28:in `execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:788:in `remove_index'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:871:in `block in method_missing'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:840:in `block in say_with_time'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:840:in `say_with_time'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:860:in `method_missing'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:604:in `method_missing'
/Users/denmark/Core/ProjectX/db/migrate/20191128014313_add_missing_unique_indices.acts_as_taggable_on_engine.rb:11:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:777:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:817:in `exec_migration'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:798:in `block (2 levels) in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:797:in `block in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:796:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:977:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1292:in `block in execute_migration_in_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1345:in `ddl_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1291:in `execute_migration_in_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1263:in `block in migrate_without_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `each'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `migrate_without_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `block in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1363:in `with_advisory_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1036:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1011:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:172:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bugsnag-6.11.1/lib/bugsnag/integrations/rake.rb:18:in `execute_with_bugsnag'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/Users/denmark/Core/ProjectX/bin/rails:9:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/denmark/Core/ProjectX/bin/spring:15:in `require'
/Users/denmark/Core/ProjectX/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
Mysql2::Error: Cannot drop index 'index_taggings_on_tag_id': needed in a foreign key constraint
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `_query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:131:in `block in query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `handle_interrupt'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/mysql2-0.5.2/lib/mysql2/client.rb:130:in `query'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:187:in `block (2 levels) in execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:186:in `block in execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:581:in `block (2 levels) in log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:580:in `block in log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:571:in `log'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:185:in `execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/mysql/database_statements.rb:28:in `execute'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:788:in `remove_index'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:871:in `block in method_missing'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:840:in `block in say_with_time'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:840:in `say_with_time'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:860:in `method_missing'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:604:in `method_missing'
/Users/denmark/Core/ProjectX/db/migrate/20191128014313_add_missing_unique_indices.acts_as_taggable_on_engine.rb:11:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:777:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:817:in `exec_migration'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:798:in `block (2 levels) in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:797:in `block in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:796:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:977:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1292:in `block in execute_migration_in_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1345:in `ddl_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1291:in `execute_migration_in_transaction'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1263:in `block in migrate_without_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `each'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `migrate_without_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `block in migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1363:in `with_advisory_lock'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1036:in `up'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/migration.rb:1011:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:172:in `migrate'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bugsnag-6.11.1/lib/bugsnag/integrations/rake.rb:18:in `execute_with_bugsnag'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/Users/denmark/Core/ProjectX/bin/rails:9:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
/Users/denmark/.rvm/gems/ruby-2.5.3/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/denmark/Core/ProjectX/bin/spring:15:in `require'
/Users/denmark/Core/ProjectX/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
@robotzhang
Copy link

Yes, it's a problem
I remove

add_index ActsAsTaggableOn.taggings_table, :tag_id

in acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb file to resolve the problem

ndrix added a commit to ndrix/acts-as-taggable-on that referenced this issue Jan 20, 2020
@ndrix
Copy link

ndrix commented Jan 20, 2020

I created a PR for this, you have top remove the foreign key prior to removing the index.

daikideal added a commit to daikideal/joblink that referenced this issue Feb 6, 2020
'AddMissingUniqueIndices'でindexを削除する際に外部キーを削除せずにインデックスを削除しようとしていたことが原因のようだ。
インデックス削除前に外部キーを削除すれば想定通りの動作になる。

参考: (mbleigh/acts-as-taggable-on#978)
      (https://teratail.com/questions/224720)
@frmsaul
Copy link

frmsaul commented Sep 23, 2020

@robotzhang @ndrix

Can you guys shed a little bit more light on this issue? What causes it exactly? Is this a problem for a particular version of rails or for all of them? What does the solution mean?

@neilabdev
Copy link

+1

2 similar comments
@tanayuk
Copy link

tanayuk commented Nov 28, 2020

+1

@jfr
Copy link

jfr commented Apr 29, 2021

+1

@mrIllo
Copy link

mrIllo commented May 10, 2021

Can be fixed with 4945323
and by re-enabling it at the end of the migration

add_foreign_key ActsAsTaggableOn.taggings_table, ActsAsTaggableOn.tags_table, column: 'tag_id'

@denmarkmeralpis
Copy link
Author

Closing this issue!

@fguillen
Copy link

Still happening to me in:

acts-as-taggable-on (7.0.0)

@2called-chaos
Copy link

Can confirm, following the install instructions in the Readme on a 6.1 project with MySQL

== 20210725152648 ActsAsTaggableOnMigration: migrating ========================
-- create_table(:tags, {:options=>"ENGINE=InnoDB", :id=>:integer})
   -> 0.0147s
-- create_table(:taggings, {:options=>"ENGINE=InnoDB", :id=>:integer})
   -> 0.0306s
-- add_index(:taggings, :tag_id)
   -> 0.0199s
-- add_index(:taggings, [:taggable_id, :taggable_type, :context], {:name=>"taggings_taggable_context_idx"})
   -> 0.0297s
== 20210725152648 ActsAsTaggableOnMigration: migrated (0.0953s) ===============

== 20210725152649 AddMissingUniqueIndices: migrating ==========================
-- add_index(:tags, :name, {:unique=>true})
   -> 0.0342s
-- index_exists?(:taggings, :tag_id, {:name=>"index_taggings_on_tag_id"})
   -> 0.0025s
-- remove_index(:taggings, :tag_id, {:name=>"index_taggings_on_tag_id"})
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Cannot drop index 'index_taggings_on_tag_id': needed in a foreign key constraint
/Users/chaos/.gem/ruby/2.7.2/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query'
/Users/chaos/.gem/ruby/2.7.2/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query'
/Users/chaos/.gem/ruby/2.7.2/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt'
/Users/chaos/.gem/ruby/2.7.2/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:206:in `block (2 levels) in execute'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:205:in `block in execute'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:695:in `block in log'
/Users/chaos/.gem/ruby/2.7.2/gems/activesupport-6.1.3.2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:687:in `log'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:204:in `execute'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/mysql/database_statements.rb:50:in `execute'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:883:in `remove_index'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:929:in `block in method_missing'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:897:in `block in say_with_time'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:897:in `say_with_time'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:918:in `method_missing'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration/compatibility.rb:263:in `remove_index'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:658:in `method_missing'
/Users/chaos/code/_private/soundtag/db/migrate/20210725152649_add_missing_unique_indices.acts_as_taggable_on_engine.rb:11:in `up'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:830:in `up'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:870:in `public_send'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:870:in `exec_migration'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:851:in `block (2 levels) in migrate'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:850:in `block in migrate'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:849:in `migrate'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1037:in `migrate'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1329:in `block in execute_migration_in_transaction'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1382:in `ddl_transaction'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1328:in `execute_migration_in_transaction'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1302:in `each'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1302:in `migrate_without_lock'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1251:in `block in migrate'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1401:in `block in with_advisory_lock'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1416:in `block in with_advisory_lock_connection'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:462:in `with_connection'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1416:in `with_advisory_lock_connection'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1397:in `with_advisory_lock'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1251:in `migrate'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1086:in `up'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/migration.rb:1061:in `migrate'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/railties/databases.rake:90:in `each'
/Users/chaos/.gem/ruby/2.7.2/gems/activerecord-6.1.3.2/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
/Users/chaos/.gem/ruby/2.7.2/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/cli/exec.rb:63:in `load'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/cli/exec.rb:63:in `kernel_load'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/cli/exec.rb:28:in `run'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/cli.rb:494:in `exec'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/cli.rb:30:in `dispatch'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/cli.rb:24:in `start'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/exe/bundle:49:in `block in <top (required)>'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/lib/bundler/friendly_errors.rb:130:in `with_friendly_errors'
/Users/chaos/.gem/ruby/2.7.2/gems/bundler-2.2.17/exe/bundle:37:in `<top (required)>'
/Users/chaos/.gem/ruby/2.7.2/bin/bundle:23:in `load'
/Users/chaos/.gem/ruby/2.7.2/bin/bundle:23:in `<main>'

Floppy added a commit to manyfold3d/manyfold that referenced this issue Jul 26, 2024
@Floppy
Copy link

Floppy commented Jul 26, 2024

Same happened for me on Rails 7.1, acts-as-taggable-on 10.0.0, MariaDB 11.4.2. The migrations work fine on PostgreSQL and SQLite, so this is a MariaDB/MySQL specific thing.

Fixed with @ndrix and @mrIllo's method of removing and re-enabling. Seems like the generator should perhaps combine those two migrations into one so that the second doesn't immediately have to alter the first?

I guess t.references :tag, foreign_key: {to_table: ActsAsTaggableOn.tags_table} in ActsAsTaggableOnMigration automatically creates an FK constraint on MySQL, whereas it doesn't get added unless done explicitly on the other two?

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

No branches or pull requests