Ticket #627 (assigned defect)
alter_column fails on postgres when removing null=True
|Reported by:||anonymous||Owned by:||andrew|
I ran into an irritation while using South to change several text columns from null=True to null=False. In this case, South generates an update like this:
ALTER TABLE "table" ALTER COLUMN "my_col" TYPE varchar(500), ALTER COLUMN "my_col" SET NOT NULL, ALTER COLUMN "my_col" SET DEFAULT %s ; [u'']
The problem is that postgres won't apply the default value to rows with NULLs and instead simply returns an error ("'my_col' contains null values"). The solution appears to be generating a quick UPDATE foo set bar = "" where bar is null beforehand, which feels like the sort of boilerplate which South should handle for you.