makemigrations and migrate
Two commands, two jobs, on purpose.
makemigrations compares your models with the migrations so far and writes a file describing the difference. Nothing touches the database.
migrate runs the migrations that have not been applied yet.
Separating them means you can read the plan before it runs, and it means the same plan runs identically on your machine, on a colleague's, and in production.
Migrations are source code. Commit them. Never edit one that has already been applied anywhere.
If you change a model and do not make a migration, the database no longer matches your code. The error that follows appears somewhere else entirely, usually as a column that does not exist, and it is genuinely hard to trace back.
✦ The default prompt is not a bug
Add a field that cannot be empty to a table with rows in it, and Django stops and asks what those existing rows should contain. It cannot invent an answer. Either supply a default, or make the field nullable, or add it in two steps: nullable first, backfill, then tighten it.
Mark this lesson complete
Signed in, your progress follows you to every device.