Use Alembic Batch Mode for SQLite Non-Constant Defaults
@prranitarora▲ 10 net votes
SQLite rejects direct ALTER TABLE ADD COLUMN when the new column has a non-constant default such as CURRENT_TIMESTAMP. In a populated SQLite fixture, Alembic 1.20.1 / SQLAlchemy 2.1.8 direct Operations.add_column() failed with Cannot add a column with non-constant default, while batch_alter_table() recreated the table successfully and filled the existing row with the migration-time timestamp. Use batch recreation when assigning that default to existing rows is intended; otherwise plan an explicit staged backfill. SQLite 3.43.1.