The migrate Command
In this page:
Applying All Pending Migrations
Running migrate with no arguments applies every migration that hasn't been applied yet, across every installed app, in the correct dependency order.
Example: Applying All Pending Migrations
Django prints 'Applying blog.0002_add_published_flag... OK' for each migration it runs against the database.
python manage.py migrate
⚠️ Run this command in your terminal.
Migrating a Single App
Passing an app name after migrate applies only that app's pending migrations, leaving the rest of the project untouched.
Example: Migrating a Single App
Only migrations belonging to the blog app are applied; other apps' pending migrations stay unapplied.
python manage.py migrate blog
⚠️ Run this command in your terminal.
How Django Tracks Applied Migrations
Django keeps a table called django_migrations that records the app and migration name for everything it has already applied, so running migrate again is always safe and won't reapply old changes.
Note: Running migrate repeatedly is harmless — it always checks this table first.
Example: How Django Tracks Applied Migrations
This queries Django's own migration-tracking table to list which blog migrations have already been recorded as applied.
python manage.py shell
>>> from django.db.migrations.recorder import MigrationRecorder
>>> MigrationRecorder.Migration.objects.filter(app='blog')
⚠️ Run this command in your terminal.
Rolling Back a Migration
Passing a specific migration name after the app rolls the database back to that point, reversing every migration applied after it.
Warning: Reversing migrations that already dropped data (like removing a column) can permanently lose that data.
Example: Rolling Back a Migration
This reverts the blog app back to the state it was in right after migration 0001, undoing 0002 and anything after it.
python manage.py migrate blog 0001
⚠️ Run this command in your terminal.
- Running migrate without ever running makemigrations first, then wondering why the database doesn't reflect a recent model change.
- Forgetting to run migrate after pulling a teammate's new migration files from version control.
- Assuming migrate re-runs every migration every time, when it only applies ones that haven't been applied yet.
- migrate applies pending migrations to the actual database.
- Django tracks which migrations have already run in a special django_migrations table.
- Running migrate again after nothing has changed does nothing — it's safe to run often.
- migrate also sets up Django's own built-in tables like auth and sessions the first time it runs.
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: