Opened 7 years ago

Closed 7 years ago

#28573 closed Bug (duplicate)

Migrations create a bad index if creating and renaming the same foreign key in one migration

Reported by: Jerome Leclanche Owned by: nobody
Component: Migrations Version: 1.11
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 (last modified by Tim Graham)

I have the following monster migration:

https://github.com/jleclanche/dj-stripe/blob/61ad7e3fa0e0b6a8ead68d892f66fc7d26edefda/djstripe/migrations/0002_card_customer_from_source.py

Putting aside most of it; when running it, I was getting the following error:

    django.db.utils.ProgrammingError: column "customer_from_source_id" does not exist

That was very confusing, but when debugging it I found out that it's choking all the way at the end on the following sql statement:

CREATE INDEX "djstripe_card_customer_from_source_id_2343e200" ON "djstripe_card" ("customer_from_source_id")

Now, that's weird because it shouldn't be creating that index on "customer_from_source_id" but on "customer_id" instead. The field is first created like so:

        migrations.AddField(
            model_name="card",
            name="customer_from_source",
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name="sources", to="djstripe.Customer"),
        ),

Then, it is renamed:

        migrations.RenameField(
            model_name="card",
            old_name="customer_from_source",
            new_name="customer",
        ),

Change History (3)

comment:1 by Tim Graham, 7 years ago

Could you try to provide a more minimal project/migration to reproduce the issue?

comment:2 by Tim Graham, 7 years ago

Description: modified (diff)

comment:3 by Tim Graham, 7 years ago

Resolution: duplicate
Status: newclosed
Type: UncategorizedBug

This looks like a duplicate of #25530 which is fixed in Django 2.0. Can you test there and if your problem isn't fixed, reopen the ticket and include a minimal project that reproduces the problem? Thanks.

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