SQLite · alpha
warning
CN · Constraints & keys
free in the CLI — --engine=sqlite
ADD COLUMN REFERENCES with a non-NULL default
Warning — it works, but holds the single write lock or breaks the previous release.
What it catches
When foreign keys are enforced (PRAGMA foreign_keys=ON, which most applications set on every connection), a column added with a REFERENCES clause must default to NULL — anything else fails with "Cannot add a REFERENCES column with non-NULL default value". Whether it fails depends on a per-connection pragma, so the same file passes in one runner and stops in another.
Fires on
ALTER TABLE orders ADD COLUMN warehouse_id INTEGER REFERENCES warehouses(id) DEFAULT 1;Do this instead
Add the referencing column with a NULL default, backfill the rows that need a value, and let the application set it from then on.
ALTER TABLE orders ADD COLUMN warehouse_id INTEGER REFERENCES warehouses(id);
-- backfill from the application, in batchesCatch this before it ships
SQLite support is in alpha: this rule runs locally in the free CLI, static only, and not in the hosted service yet: npx bolvrk check migration.sql --engine=sqlite