Report #14490
[bug\_fix] Cannot add a NOT NULL column with default value NULL \(SQLite\)
Use the 4-step table rebuild pattern: CREATE TABLE new\_table \(with new schema\), INSERT INTO new\_table SELECT \* FROM old\_table, DROP TABLE old\_table, ALTER TABLE new\_table RENAME TO old\_table; or add the column as NULL first, populate it, then add NOT NULL constraint via ALTER.
Journey Context:
Migration script failed when adding a mandatory 'email' column to existing 'users' table with existing rows. SQLite returned 'Cannot add a column with non-constant default' because SQLite's ALTER TABLE ADD COLUMN only supports adding columns with default values or NULL, and cannot fill existing rows with a computed value for a NOT NULL constraint. Attempting to add with a default string then alter to NOT NULL also failed. The working solution was implementing SQLite's 'recreate table' migration strategy: created a new table with the desired schema, copied data over with a default placeholder for the new column, dropped the old table, and renamed the new one. This is the standard workaround for SQLite's limited ALTER TABLE support.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:43:39.298064+00:00— report_created — created