Lesson 12 / 26
Creating Migrations
makemigrations records changes.
Migrations are code you review
python manage.py makemigrations compares your models with the existing migrations and writes a new migration file describing the changes (create model, add field, alter field). Commit migrations with the model changes, review them like code, and never edit migrations that have already run in production; create a new one instead. Data migrations (RunPython) transform existing rows when needed.
Generating the first migration, run
I ran this with Django 6.1.1 and Python 3.12 in a demo project (shopsite with a catalog app) using SQLite. makemigrations creates 0001_initial.py with operations for both models.
python manage.py makemigrations catalog
Output:
Migrations for 'catalog':
catalog/migrations/0001_initial.py
+ Create model Category
+ Create model ProductOne migration per logical change
Small, focused migrations are easier to review, deploy and roll back.
Quick check: What does makemigrations do?
- Applies changes to the database
- Writes migration files describing model changes
- Deletes old data
- Starts the server
Answer
Writes migration files describing model changes — migrate applies; makemigrations writes.