The migration failed at row 1024. The log kept repeating one phrase: “no such column.” Adding a new column should have been simple. But simple tasks fail when schema changes collide with live data and production load.
A new column in a database can break queries, slow writes, and lock tables if not done with intent. The safest approach starts with knowing how your database engine handles schema changes. In PostgreSQL, adding a column with a default that is not NULL rewrites the whole table. In MySQL, ALTER TABLE can block operations unless paired with algorithms like INPLACE or tools like pt-online-schema-change.
Define the new column with the smallest viable type. Avoid BLOB or TEXT unless required. Set constraints carefully; a NOT NULL column with default values is usually safer than one populated with application logic post-deployment.
For high-traffic systems, deploy schema changes in stages. First, add the new column as nullable with no default. Second, backfill data in controlled batches to prevent cache churn and lock contention. Third, apply constraints and defaults in a subsequent migration once data consistency is verified.