Skip to content

Scaffolding: fix default value & nullability issue

When having postgres table column with not null being false, null is a default value until defined differently (ref (second paragraph)). But, asking pg_attribute.atthasdef (in PostgresReflector) results in false in such case as it handles null as a default value implicitly (ref (last paragraph)).

When you try to run ALTER TABLE x ALTER COLUMN y SET DEFAULT NULL; in SQL console, it writes "OK", but default value is still visually empty in both PhpStorm dialog or pgAdmin dialog. That confirms the null implicity.

Thus we have to rely not only on pg_attribute.atthasdef, but on nullability (pg_attribute.attnotnull) as well.