Opened 7 years ago
Last modified 7 years ago
#28573 closed Bug
Migrations create a bad index if creating and renaming the same foreign key in one migration — at Initial Version
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
I have the following monster migration:
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",
),