The migration halted when the query failed. A missing column. The logs offered no clues beyond the cold error code. You need a new column, and you need it without breaking production.
Adding a new column is one of the most common database schema changes. Done wrong, it locks tables, slows writes, and cascades into downtime. Done right, it’s invisible to end users and safe for live traffic.
Before creating a new column, define its data type and constraints. Choose the smallest type that can hold the data, to keep indexes lean and queries fast. Decide if the new column should allow nulls or have a default value. Defaults applied to large tables can trigger full table rewrites—migrate those in stages if possible.
Use transactional DDL if your database supports it. In PostgreSQL, ALTER TABLE ... ADD COLUMN is fast for null-allowed columns without defaults. For MySQL, online DDL with ALGORITHM=INPLACE can prevent locking during the new column creation. For massive datasets, break the change into steps: