13

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?

Han He
  • 3,391
  • 3
  • 24
  • 25

1 Answers1

22

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.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Thanks for your answer, it's a good solution for my situation while the `./manage.py migrate ` should be `./manage.py makemigrations`. Just wondering if Django has any configuration to control this order instead of manually running `makemigrations` for the apps. – Han He Sep 19 '15 at 13:40
  • But it also detects changes in other apps – Mohammed Shareef C Dec 01 '19 at 07:50