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 versioned script that changes the schema (create tables, add columns) in a repeatable way. Migrations live in source control and run in order on every environment.

The concept

Each migration has an up (apply) and usually a down (revert) step. The tool records which have run in a migrations table.

This keeps developers' local databases, staging and production in sync and makes schema changes reviewable.

Versioned history

php artisan migrate
2026_09_16_create_articles_table ........ DONE
2026_10_01_add_views_to_articles ........ DONE

Practical examples

Laravel migration

Schema::table('articles', function (Blueprint $t) {
  $t->unsignedInteger('views')->default(0)->after('title');
});

Rollback

php artisan migrate:rollback --step=1

Safe changes in production

Add nullable column → deploy code → backfill → add constraint

Common mistakes

  • Editing a migration that already ran elsewhere.
  • Destructive changes without backups.
  • Long locks on big tables.

Key takeaways

  • Schema changes as versioned code.
  • Never edit applied migrations.
  • Plan zero-downtime changes.

FAQ

Migration vs seeder?

Migrations change structure; seeders insert data.

Can I roll back in production?

Possible, but test the down step and keep backups.

More SQL articles