I'm using Django 1.8.4. As my project is still under construction, I frequently remove all migration scripts, and rerun makemigrations
to generate the initial migration scripts.
I found makemigrations
would generate two migration scripts for one of my apps while other apps just have 0001_initial.py
. It would be something like:
- 0001_initial.py
- 0002_auto_20150919_1645.py
I checked the content of 0002_auto_20150919_1645.py
, it was adding foreign field from the other app's model.
I guess it might be related to the order of creating migrations for apps. So I delete these two migration scripts of this app and then run makemigrations
again. Now I have only one migration script for this app.
My questions is:
Is there any way I can control the order makemigrations
create migrations for apps?
For example, I have two apps, app1
and app2
, and app1
depends on app2
. Is it possible makemigrations
create migration for app2
first, and then app1
?
Ensuring that a migration is applied only once requires keeping track of the migrations that have been applied. Django uses a database table called django_migrations . Django automatically creates this table in your database the first time you apply any migrations.
makemigrations is responsible for packaging up your model changes into individual migration files - analogous to commits - and migrate is responsible for applying those to your database.
This may happen due to the following reasons: You did not add the app in INSTALLED_APPS list in settings.py (You have to add either the app name or the dotted path to the subclass of AppConfig in apps.py in the app folder, depending on the version of django you are using). Refer documentation: INSTALLED_APPS.
You can manually run migrations for an individual app.
./manage.py makemigrations app2
./manage.py makemigrations app1
./manage.py makemigrations # migrate the rest of your apps
You could also squash your existing migrations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With