Order in django migration

we are working on a web application in which there is one central application, and the new one we added last.

The transfer procedure is as follows:

contenttypes 0001 
contenttypes 0002

auth         0001
...
auth         0006

main_app     0001
...
main_app     0045

After adding a new application, the transfer order was as follows:

contenttypes 0001
auth         0001
main_app     0001
...
main_app     0045
contenttypes 0002
auth         0002
...
auth         0006
new_app      0001

There are several things worth noting:

  • new_app.0001 Migration has dependencies (in this order):

    auth.0006
    main_app.0045
    

    And just create a foreign key for the user.

  • auth.0004 migration updates username to have a maximum length of 30

  • my_app.0012delete the field user.usernameto have a length of 255 (via some AlterField-derived class )

So, due to the order in which the migration is performed, without new_app, the total length user.usernameis 30 instead of 255.

In the initial migration, my_appwe have the following relationship:

migrations.swappable_dependency(settings.AUTH_USER_MODEL)

(, , django ).

: ? ?

. "" , my_app:

migrations.swappable_dependency(settings.AUTH_USER_MODEL),
auth.0006

, , .

+4
1

Django , , . , .

, . , , . , docs.

+3

All Articles