makemigrations vs migrate (Django)

makemigrations and migrate are the two Django commands that manage schema changes. makemigrations generates migration files from your model changes; migrate applies those files to the actual database. You almost always run them in that order.

Django

The split exists because creating a migration and applying it are separate concerns. makemigrations only writes a file describing what changed — it never touches the database — so you can review and commit it. migrate reads pending migration files and executes their SQL against the database.

Typical flow: edit models.py, run makemigrations (Django asks about ambiguous changes, like a new non-null field needing a default), commit the generated file, then run migrate locally and on each server. New environments run migrate to build the schema from scratch.

A common confusion is running only one of them. makemigrations without migrate leaves the database unchanged; migrate without an up-to-date migration file misses your latest model edits. Run makemigrations after every model change, then migrate to apply.

Syntax

python manage.py makemigrations  # create file
python manage.py migrate          # apply

Examples

Python

# see what SQL a migration would run
python manage.py sqlmigrate blog 0003

# show migration status
python manage.py showmigrations

# create then apply
python manage.py makemigrations
python manage.py migrate

Learn it in a lesson

See also

Back to the Dictionary