Skip to content

MG04 — ADD COLUMN NOT NULL without a DEFAULT fails on a non-empty table

Group: Migration safety · Auto-fixable: no

A NOT NULL column added without a default has no value for existing rows, so the statement errors on any table that already has data. Provide a DEFAULT, or add the column nullable and set NOT NULL after backfilling.

bad: ALTER TABLE t ADD COLUMN c int NOT NULL;
good: ALTER TABLE t ADD COLUMN c int NOT NULL DEFAULT 0;

Disable this rule in banshee.toml:

[lint]
exclude = ["MG04"]

Or silence one line with -- noqa: MG04. See Linting.