Can anyone explain me, how migration will happened in django? Actually I want full backend procedure of "./manage.py migrate" command
1 Answers
It was explained once at the "django under the hood" conference by the author. I have a summary of that: http://reinout.vanrees.org/weblog/2014/11/14/2migrations.html
The way it works is by chopping all operations into tiny dependencies. Every individual field that has to be created is turned into a tiny dependency step. After the list of steps is sorted (via the dependency-resolving loop) into the correct list of steps, an optimiser goes through the list and optimises it. If a model gets created and deleted, nothing needs to be done, for instance.
The final part of the puzzle is the graph. It builds a directed graph of all basic migrations in memory. It needs to read all the models on disk for that. It also looks in the database. There’s a table in there that marks which migrations (or rather: nodes in the migration graph) have been applied.
If you want to look at the code, here are some pointers:
django/db/migrations/autodetector.py
, start at _detect_changes()django/db/migrations/optimizer.py
, start at reduce()django/db/migrations/graph.py
django/db/migrations/loader.py

- 13,486
- 2
- 36
- 68
-
**Editorial note**: this answer was at first just the first paragraph with the link. When I added the rest of the answer two minutes later, it was already downvoted twice. Sorry for not submitting the answer in one go. – Reinout van Rees Feb 23 '17 at 08:03
-
Thank you @Reinout van Rees – Prafulla Feb 23 '17 at 09:37