Django Tips #1: makemigrations command
This post is the start of a little series called Django Tips, answers to short, common questions I receive from readers.
Question: Why do we explicitly call
python manage.py makemigrations users instead of just
python manage.py makemigrations in DjangoX?
Answer: This pattern is also used in my books and for good reason. When you just type
python makemigrations then ALL existing migrations are run. This can be a problem if you have made changes to multiple apps, for example
users and also
blog. The resulting migrations file will contain information on BOTH which makes it harder to debug issues in the future. The goal is to keep every migration as concise and atomic as possible.
If you add the specific app name to the end of the command, so
python makemigrations user then only the migrations for that specific app are run. After you can run
python makemigrations blog if you have two different changes ready to commit.
So get in the habit of being explicit with every migration file you recreate. It’s a best practice that will help you down the road.