Unit IV · Your data
Changing the shape safely
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
Checked October 17, 2026. Pages on other sites change; if a source no longer says what the lesson says, the source wins.