After ADD FOREIGN KEY NOT VALID, historical invoice 11 still points to missing customer 99, but new invoice 12 with the same reference is rejected. Historical validation and deferred checking are separate decisions.

A foreign key refuses to let a reference dangle

Adding a PostgreSQL foreign key to an existing table is both a schema change and a statement about old data. New writes can be checked immediately while historical rows still contain broken references. Separate the constraint’s enforcement, its validation state, and its checking time when planning a migration or diagnosing an unexpected integrity failure. ...

January 2, 2027 · 6 min · XB Field Notes