#35305: No-op rename of field with `db_column` drops and recreates constraints
------------------------------------------------+------------------------
Reporter: Jacob Walls | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 4.2
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 |
------------------------------------------------+------------------------
With this model:
{{{
class MyModel(models.Model):
foo = models.BooleanField(db_column="foobar")
class Meta:
constraints = [
models.UniqueConstraint(
fields=["foo"],
name="unique_foo",
),
]
}}}
Suppose I wish to improve the name of the field so it agrees with the
database column name:
{{{
class MyModel(models.Model):
foobar = models.BooleanField(db_column="foobar")
class Meta:
constraints = [
models.UniqueConstraint(
fields=["foobar"],
name="unique_foo",
),
]
}}}
That change generates a migration with this SQL, assuming you answer "was
the field ... renamed..." with Yes:
{{{
BEGIN;
--
-- Remove constraint unique_foo from model mymodel
--
ALTER TABLE "models_mymodel" DROP CONSTRAINT "unique_foo";
--
-- Rename field foo on mymodel to foobar
--
-- (no-op)
--
-- Create constraint unique_foo on model mymodel
--
ALTER TABLE "models_mymodel" ADD CONSTRAINT "unique_foo" UNIQUE
("foobar");
COMMIT;
}}}
Suggesting that we compare on `db_column` if present to allow this kind of
change to be a no-op with respect to constraints.
--
Ticket URL: <https://code.djangoproject.com/ticket/35305>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018e42878eb6-a2fa0d1a-ae19-4853-95c1-269a715f62d5-000000%40eu-central-1.amazonses.com.