The migration failed because the schema didn’t match. You check the logs. The error is clear: missing column. You roll back. The fix is simple—add a new column.
A new column changes the shape of your data. In SQL, it means altering the table with an ALTER TABLE statement. In NoSQL, it can mean updating the document structure or introducing default fields. The goal is the same: extend the model without breaking existing queries.
When adding a new column in PostgreSQL, use:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
This keeps existing rows valid, sets a default, and ensures new inserts comply. Avoid null traps by setting defaults whenever possible. Use a transaction for safety.
In MySQL, the syntax is similar, but be mindful of engine-specific performance impacts. Large tables can lock during the operation. Mitigate this with online schema changes or tools like pt-online-schema-change.