Han He
Han He

Reputation: 3461

Django makemigrations app order

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?

Upvotes: 14

Views: 21448

Answers (1)

Alasdair
Alasdair

Reputation: 308919

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.

Upvotes: 22

Related Questions