Migrating in django is sometimes tricky and a bit less intuitive if youhave come fromsomething like
Create the model class in
Make sure the
appis added to
Create the migration
RunPython is a way to initialise data or run operations during migrations. They are tightly coupled with migrations and can be viewed here: RunPython docs
Reversing all migrations to Zero#
./manage.py migrate <app_name> zero
Say for example you are playing around with the model and make multiple changes and multiple migrations before deciding on the correct way.
You will probably see something like this in
Untracked files: (use "git add <file>..." to include in what will be committed) entries/migrations/0006_auto_20171106_0930.py entries/migrations/0007_auto_20171106_0938.py entries/migrations/0008_auto_20171106_0939.py entries/migrations/0009_auto_20171106_1004.py
Now you want to remove these testing migrations and just apply a single one.
It can be done by unapplying migrations to a specific version with:
./manage.py migrate <app_name> <migration_name> ./manage.py migrate entries 0005_auto_20171103_1341
You can then delete the migrations and create a single one afresh with:
./manage.py makemigrations ./manage.py migrate