liveBook · Manning

--empty flag

As explained in Django in Action

The makemigrations command-line option that creates an empty migration file without operations.

Django’s makemigrations --empty option creates a migration file with no operations. Think of it as an intentionally blank checkpoint: the migration system handles its place in the dependency chain, while you add custom work such as data transformation. section 10.6

Use the flag when you need to:

  • Create a stub for a RunPython operation that changes existing rows. section 10.6
  • Place data-copying logic after a schema migration has added the destination fields. section 10.2
  • Write forward and backward functions when the data transformation can be reversed. section 10.2

Create a custom migration stub

Run the command from the project directory: python manage.py makemigrations --empty promoters Django generates a migration such as promoters/migrations/0004_auto_20230904_1552.py. You can rename it to a clearer filename, such as 0004_data_fullname.py, then add the dependency and custom operation. The generated starting point contains an empty operations list, so nothing changes in the database until you edit the file. section 10.2

How Django in Action covers it

How deep it goes
Explains command usage, generated structure, dependencies, and its role before RunPython data transformations.
Examples
Demonstrates creating and renaming a promoters migration before copying name data between fields.
What it assumes
Builds on an existing schema migration and its dependency before introducing custom data-migration code.
What you can do after
Operate/configure Django migrations by creating a named stub for custom RunPython data changes.
How it connects
Connects empty migrations with makemigrations, RunPython, migration dependencies, and reversible database changes.

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.