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

When renaming a model, migration has error with indexes #142

Open
mdkarp opened this issue Mar 8, 2015 · 2 comments
Open

When renaming a model, migration has error with indexes #142

mdkarp opened this issue Mar 8, 2015 · 2 comments

Comments

@mdkarp
Copy link

mdkarp commented Mar 8, 2015

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'

@iox
Copy link
Member

iox commented Mar 9, 2015

Nice bug description Mike, thanks!

@hbaragar
Copy link

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.

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

3 participants