Keelmark Your record

Unit IV · Your data

Changing the shape safely

Lesson 11 of 185 minSources checked Oct 17, 2026

Sooner or later you add a column or a table to a live database. Migrations make those changes as ordered files that run the same way everywhere.

What a migration is

A migration is a small file that changes the database's structure: add a table, add a column, add an index. Frameworks such as Rails, Django and Laravel record which migrations have run, so every environment gets the same changes in the same order.

Rules that keep production safe

Back up before migrating production. Do not edit a migration that has already run in production; write a new one instead (the Rails guide warns that editing an existing migration causes major headaches once it has run on production machines). Try the migration on a copy with realistic amounts of data first, and time it: a change that is instant on a small test table can take much longer on a big one.

Going back

Many migrations can be rolled back, but a change that drops a column also deletes its data, and rolling back the structure does not bring the data back. That is what the backup is for.

Words to know

Schema
the structure of the database: tables, columns, types, keys
Migration
a file that changes the schema
Rollback
undoing a migration's structural change
Index
a lookup structure that makes searching a column faster

Sources

  1. Rails Guides: Active Record Migrations
  2. Django documentation: Migrations

Checked October 17, 2026. Pages on other sites change; if a source no longer says what the lesson says, the source wins.

Lesson check

Two questions. Answer both correctly to pass this lesson. You can try as often as you like.

1A migration already ran in production and you need one more change. What do you do?
2What must you do before migrating a production database?