New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
Adding a NOT NULL column to a table that's already full and read constantly, without taking the site down.
What you'll have at the end
A required column added to a live table with zero blocked reads or writes, confirmed by watching active queries during the change
You need
A Postgres table with real read and write traffic already hitting it, reachable through a SQLAlchemy model and an Alembic migration setup, and a rule for turning each existing row's own data into the new column's value.
Not covered
Turning the new column into a foreign key with its own referential check; that follows the same unvalidated-then-validated pattern this recipe uses, but as its own separate migration.
Leans on
Know when to drop to raw SQL
if hand-written statements like these are becoming the norm across your migrations rather than the exception, that recipe covers deciding when to lean on raw SQL generally.
Bulk-insert ten thousand rows without timing out the import
the same small-batches-committed-often discipline used here for an update backfill applies to a bulk insert job too, with its own separate pitfalls.
Checked 18 Aug 2026
Part of the ORM and Database Abstraction Tools cookbook