The migration failed at row 327. The error log showed a single line: unknown column. You check the schema. The column doesn’t exist. You need a new column. Now.
Adding a new column sounds simple, but in production, it can decide uptime, performance, and data integrity. Schema changes are code changes. They need to be fast, reversible, and safe.
The first step is knowing the constraints of your database engine. MySQL supports ALTER TABLE ADD COLUMN with instant or in-place algorithms for certain data types. PostgreSQL allows adding new columns with a default value as NULL instantly, but setting a non-nullable default will rewrite the entire table. This distinction matters when rows count in the millions.
Plan backward from the deployment window. Create a migration script that adds the new column with no defaults. Backfill data in controlled batches. Once complete, enforce constraints in a second migration. This isolates risk, keeps locks small, and prevents long blocking operations.