#35962: Migration crashes when attempting to remove constraint on already removed
foreign key
-----------------------------+--------------------------------------
Reporter: Jacob Walls | Type: Bug
Status: new | Component: Migrations
Version: dev | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Same issue as #34333, just for `RemoveField` & `RemoveConstraint` instead
of `AddField` and `AddConstraint`.
Reproduction:
Repeat steps 1-4 of #34333.
5. Restore models.py to step 1 and make a third migration.
Migration will look like:
{{{#!python
# Generated by Django 5.2.dev20241129120448 on 2024-12-01 20:41
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("other", "0002_category_model_category_and_more"),
]
operations = [
migrations.RemoveField(
model_name="model",
name="category",
),
migrations.RemoveConstraint(
model_name="model",
name="unique_category_for_date",
),
migrations.DeleteModel(
name="Category",
),
]
}}}
And will crash as follows:
{{{#!python
django.db.utils.ProgrammingError: constraint "unique_category_for_date" of
relation "other_model" does not exist
}}}
Succeeds if the `RemoveConstraint` and `RemoveField` are manually
reordered.
Tested on Postgres 16.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35962>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.