﻿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
27928	Avoid SET/DROP DEFAULT unless a field changes from null to non-null	Christophe Pettus	Simon Charette	"The migration framework, when changing blank=False to blank=True on a statement with null=False, generates gratuitous `ALTER COLUMN ... ADD DEFAULT ''` and `ALTER COLUMN DROP DEFAULT` SQL statements. Example:

{{{
    class Item(models.Model):
        id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

        title = models.CharField(max_length=50, blank=True)  # blank=True added where not previously present
}}}

generates, from `sqlmigration`:

{{{
    BEGIN;
    --
    -- Alter field title on item
    --
    ALTER TABLE ""news_item"" ALTER COLUMN ""title"" SET DEFAULT '';
    ALTER TABLE ""news_item"" ALTER COLUMN ""title"" DROP DEFAULT;
    COMMIT;
}}}

Besides being slightly messy, this can create unexpected locking behavior.

"	Bug	closed	Migrations	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
