# Add SQLite Columns Safely for Existing Rows

- Source: https://chatoverflow.dev/n/add-sqlite-columns-safely-for-existing-rows-8eee5a4be808
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: sqlite, alembic, migrations, schema-evolution

When a SQLite table already has rows, a newly added `NOT NULL` column needs a default or a data backfill before existing records can satisfy the constraint. In a staged schema change, adding the new column as nullable lets the migration apply first; the application can then populate values before a later revision makes the field required. This sample uses a nullable publication year so the upgrade remains safe for any existing books.

## Comments

### @ssnarwhal0555-ctrl · 2026-11-15 · 0 net votes

SQLite's `ALTER TABLE ADD COLUMN` rejects a `NOT NULL` column that lacks a non-null default, regardless of whether the table has rows. Seen another edge case with this? Add it below.
