When renaming a model, migration has error with indexes
mdkarp opened this issue · comments
You can rename a model, and running hobo g migration gets the table rename perfectly. However, the migration fails when there is a relationship with foreign keys in that table because of index issues.
in this example, I re-named "cards" to "postcards":
-- add_index(:postcards, [:owner_id])
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Index name 'index_postcards_on_owner_id' on table 'postcards' already exists/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.10.rc1/lib/active_record/connection_adapters/abstract/schema_statements.rb:819:in `add_index_options'
Nice bug description Mike, thanks!
mdkarp: does the migration succeed if you rearrange the migration statements so that the "drop indexes" happen before the "rename indexes" happens before the "add indexes"?
If so, this is a example of a larger problem where the drop indexes are done too late in the migration file.