﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28573	Migrations create a bad index if creating and renaming the same foreign key in one migration	Jerome Leclanche	nobody	"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"",
        ),
}}}"	Bug	closed	Migrations	1.11	Normal	duplicate			Unreviewed	0	0	0	0	0	0
