← Back to Django Course | Chapter 5: Migrations & Database Management | Lesson 2 of 8

The makemigrations Command

makemigrations looks at your models and writes a set of instructions describing what changed since last time.

Running makemigrations

From your project's root folder (where manage.py lives), running makemigrations compares your current models.py against the last recorded migration and writes a new file for anything that changed.

Example: Running makemigrations

Django scans all installed apps and prints something like 'Migrations for blog: 0002_article_published.py' for each change it found.

bash
python manage.py makemigrations

⚠️ Run this command in your terminal.

Targeting a Single App

Passing an app's name after makemigrations restricts the scan to just that app, which is useful in a large project with many apps.

Example: Targeting a Single App

Only the blog app's models are checked; other installed apps are left untouched even if they also changed.

bash
python manage.py makemigrations blog

⚠️ Run this command in your terminal.

Reading the Output

makemigrations prints the app name and the new migration filename it created, plus a short list of what each operation does, so you can sanity-check the change before applying it.

Warning: Read the printed operation list carefully — it tells you exactly what will happen to your tables.

Example: Reading the Output

The comment lines show Django's own explanation of the change it detected, matching the new BooleanField added to the model.

bash
python manage.py makemigrations
# Migrations for 'blog':
#   blog/migrations/0002_article_published.py
#     - Add field published to article

⚠️ Run this command in your terminal.

Naming a Migration

The --name flag lets you give a migration a meaningful name instead of Django's auto-generated one, which makes the migrations folder easier to read later.

Example: Naming a Migration

The resulting file is named 0002_add_published_flag.py instead of an auto-generated description.

bash
python manage.py makemigrations blog --name add_published_flag

⚠️ Run this command in your terminal.

Common Mistakes
  1. Running makemigrations but forgetting to run migrate afterward, so the database never actually receives the change.
  2. Editing a model field's name directly and assuming Django will silently detect it as a rename instead of asking whether it's a rename or a new field.
  3. Running makemigrations for one app and expecting it to also pick up changes in unrelated apps that weren't touched.
Chapter Summary
  • makemigrations scans every app in INSTALLED_APPS for model changes.
  • It writes a new numbered file into that app's migrations/ folder.
  • It does not touch the database itself — that's migrate's job.
  • You can target a single app by name to only check that app.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.