Problem description

How to deal with model class migration in the case that several developers modify the same model class at the same time in the collaborative development project, for example:

  • A developer: Add one to the branch 1 project code"author"To ABCModel, and there you have itmigration 0003_blog_blog.py
  • B Developer: Add one to the branch 2 project code"content"Field to ABCModel, and there you have it0003_blog_content.py

How do I perform the migration files after merging the code? Both files are numbered 0003?

Problem solving

  • Plan 1
    • Trying to performpython manage.py migrate
    • Django will prompt you to execute in case of a file conflictpython manage.py migrations -mergeA merger
    • This is generated in the Migration folder after the merge is performed0004_merge.py
    • performpython manage.py migratePerform a post-merge migration
  • Scheme 2
    • usepython manage.py migrate [APPName] [migrationNumber]Specify APP specifies that the migrated file is rolled back to the last stable migration state
    • Regenerate the migration file for migrationpython manage.py migrations
    • performpython manage.py migratePerform the migration
  • Plan 3
    • Development projects can be onmigrationFolder to ignore
    • Development simply involves merging the code, generating a unified migration file, and performing the migration


Exploring problems is also a way for you to grow