What Is a Database Migration?

A database migration is a version-controlled file describing an incremental change to a database schema, like creating a table or adding a column, that can b...

Published October 9, 2026

A database migration is a version-controlled file describing an incremental change to a database schema, like creating a table or adding a column, that can be applied and reversed in a defined order.

Why it exists

  • Manually running ad hoc SQL changes against a database makes it hard to know exactly what schema state any given environment (local, staging, production) is actually in
  • Migrations turn schema changes into ordered, trackable code, applied consistently across every environment

How to apply it

  • Write each schema change as its own migration file with both an "up" (apply) and "down" (reverse) method
  • Never edit an already-applied migration that's been shared with others — write a new migration to make further changes instead

FAQ

What happens if two developers create conflicting migrations?

Most migration tools order migrations by timestamp or sequence number, so conflicts show up as an ordering or naming collision that needs to be resolved manually, similar to a merge conflict.

More SQL articles