aerich
aerich copied to clipboard
Aerich does not set defaults when migrating postgres databases
When I add a default to a column that did not have a default, aerich will not add the default. It will write ALTER TABLE "<tablename>" ALTER COLUMN "<columnname>" SET;, which not only does not contain the default but also is a syntax error.
The default is a value or callable?
The default is a string.
It also a problem for JSONB fields.
some_field = fields.JSONField( default=[], null=False )
produces migration:
ALTER TABLE "some_table" ADD "some_field" JSONB NOT NULL
which causes error:
tortoise.exceptions.IntegrityError: column "some_field" of relation "some_table" contains null values
The correct migration should be:
ALTER TABLE "some_table" ADD "some_field" JSONB NOT NULL DEFAULT '[]';