Opened 8 years ago

Closed 8 years ago

#25863 closed Bug (duplicate)

RenameModel migration does not rename indexes, subsequent index creation fails

Reported by: Jiri Baum Owned by: nobody
Component: Migrations Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Django RenameModel operation does not rename indexes; this can lead to index name collisions later if the old model name is reused.

Steps to reproduce:

  • Make a model "A" with at least one index (db_index=True or index_together or unique_together).
    • python manage.py makemigrations
  • Rename model "A" to "B".
    • python manage.py makemigrations
  • Create new model called "A", with some of the same fields and indexes.
    • python manage.py makemigrations
  • Run tests (no tests need to exist for this step).
    • python manage.py test

Observed behaviour: django.db.utils.OperationalError: index polls_question_b61a98bd already exists

Expected behaviour: "Ran 0 tests in 0.000s OK"

Comments:

  • This is a regression; these steps do not give an error under Django 1.8.
    • I initially saw the error on upgrading to 1.9 and running the tests with already-existing migrations.
    • I have not checked whether the operation under Django 1.8 is correct, certainly the indexes are not renamed, but they do not give an error in normal use or in the test. It is possible that some corner cases in 1.8 will operate on the wrong index in this scenario.
  • Our use case is that we renamed a model Foo to FooRaw, then created a new model Foo to contain a processed version of the data.

Change History (3)

comment:1 by Simon Charette, 8 years ago

Component: UncategorizedMigrations

This looks really similar to #23577, are you sure this is a regression in 1.9?

comment:2 by Jiri Baum, 8 years ago

Hmm, I'm sure it's a regression, but (on checking more carefully) it's not demonstrated by my steps-to-reproduce...

I have a project where the tests pass in 1.8 and fail with this error in 1.9.

However, now that I check more carefully, following my steps-to-reproduce in 1.8 also gives the error.

I'll have to have another check on the regression aspect on Monday.

comment:3 by Tim Graham, 8 years ago

Resolution: duplicate
Status: newclosed

I'll mark it as a duplicate of #23577 for now. Feel free to open a new ticket if the regression is some other issue. In either case, I'll be happy to backport a patch to fix the issue.

Note: See TracTickets for help on using tickets.
Back to Top