﻿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
35305	No-op rename of field with `db_column` drops and recreates constraints/indexes.	Jacob Walls	Jacob Walls	"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."	Cleanup/optimization	closed	Migrations	4.2	Normal	fixed			Ready for checkin	1	0	0	0	0	0
