# Database Migration

> A small file that makes one change to a database's shape. It lives with the code.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** Schema Migration, Migration, Migration File

## Think of it like

Think of it like a list of steps to rearrange a room. Anyone can follow it and end up with the same room.

## Definition

A database migration is a small file that changes the schema. Each one makes a single change, like adding a column. Each migration is saved in Git with the code that needs it. A tool runs the ones a database has not had yet, in order. That way, every laptop, test server and live server ends up with the same schema. Most migrations also say how to undo the change.

## Example

Jack adds a phone field to his app. He writes a migration, and when he deploys, the live database gets the new column too.

## Example code

```sql
-- 0007_add_phone.sql
ALTER TABLE customers ADD COLUMN phone TEXT;
```

The file adds one column called phone.

## Why it matters

Without migrations, each copy of the database drifts. Then code that works on your laptop breaks on the server.

## Common mistake

Editing a migration that has run on the live server. Write a new one, or the copies will not match.

## Three principles

- **One step each.** Small changes, in order.
- **Kept in Git.** Next to the code that needs them.
- **Never edit old ones.** Add a new step instead.

## Related terms

- [Database Schema](https://learn.benibix.com/term/development/schema)
- [Column](https://learn.benibix.com/term/development/column)
- [Object-Relational Mapping (ORM)](https://learn.benibix.com/term/development/orm)
- [Commit](https://learn.benibix.com/term/development/commit)

---

Source: https://learn.benibix.com/term/development/database-migration
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
