Skip to content
IT glossary
DatabasesUpdated December 3, 2026

Database migration

Миграция базы данных

A controlled change to a database’s structure, such as adding a column or an index. It can also update existing records so they work with the new structure.

Also known as: миграция схемы

What is a database migration?

A database schema defines how data is organized and what rules it must follow: which tables exist, what types their columns hold, and which values are required or unique. A migration is a recorded step from one database state to another. It might create a table, add an index, or fill in existing rows before a new rule takes effect. In application development, “database migration” usually means this kind of schema change, not moving a database to a new server.

How migrations are applied

Teams usually commit migration files alongside the application code. The files can contain SQL or use a framework’s migration API. Tools such as Flyway, Liquibase, and Django’s migration system track what each database has already applied. When run, they use that history to apply pending changes in version or dependency order. This lets developers test a change in staging and then apply the same change in production. If a migration has already been shared and applied, add a new migration to fix it rather than editing the old one: editing a file does not update databases that have already run it.

Example: add a column before the app needs it

Suppose an orders service needs to store a delivery note. In PostgreSQL, the first migration could be:

ALTER TABLE orders ADD COLUMN delivery_note text;

Existing orders have NULL in the new column. An older app version that names only the original columns in its INSERT statements can continue to create orders. Once the column exists, the new app can start saving notes. If the product later requires a note on every order, treat that as a separate change: update all writers, determine what valid value belongs in historical rows, backfill those rows, and only then enforce NOT NULL. If no valid historical value exists, the data model may need to keep the field optional.

Production risks and common mistakes

A short SQL statement can still take a lock that blocks other queries, and a large backfill can compete with live traffic. Test against realistic data volumes, check the database engine’s locking behavior, and make large backfills resumable in batches. Also distinguish a failed migration from a bad release. Some databases can roll back certain schema changes inside a transaction, but rolling back application code does not undo a committed migration. Recreating a dropped column brings back its definition, not its contents.

What interviewers look for

A common prompt is how to rename a column during a rolling deployment. A direct rename can break instances still using the old name. A safer approach is expand and contract: add the new column, keep the two columns in sync while backfilling old rows, verify the result, and switch readers to the new column. Remove the old one in a later release, after confirming that no app instances or background jobs still depend on it.