Support rename_table
sue445 opened this issue · 0 comments
sue445 commented
Migrations
class CreateOldTable < ActiveRecord::CompatibleLegacyMigration.migration_class
include ActiveRecord::SimpleIndexName::EnableShorten
def change
create_table :old_table do |t|
t.string :anonymous_name, null: false
t.timestamps null: false
end
add_index :old_table, :anonymous_name
end
end
class RenameOldTableToNewTable < ActiveRecord::CompatibleLegacyMigration.migration_class
def change
rename_table :old_table, :new_table
end
end
Error
1) ActiveRecord::ConnectionAdapters::SchemaStatements#index_name_with_simple When auto_shorten is enabled When single column index
Failure/Error: rename_table :old_table, :new_table
StandardError:
An error has occurred, this and all later migrations canceled:
Index name 'anonymous_name' on table 'new_table' already exists
# ./vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:939:in `add_index_options'
# ./vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:556:in `add_index'
# ./vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:598:in `rename_index'
# ./vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:998:in `block in rename_table_indexes'
# ./vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:995:in `each'
# ./vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:995:in `rename_table_indexes'