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 perform
python manage.py migrate
- Django will prompt you to execute in case of a file conflict
python manage.py migrations -merge
A merger - This is generated in the Migration folder after the merge is performed
0004_merge.py
- perform
python manage.py migrate
Perform a post-merge migration
- Trying to perform
- Scheme 2
- use
python 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 migration
python manage.py migrations
- perform
python manage.py migrate
Perform the migration
- use
- Plan 3
- Development projects can be on
migration
Folder to ignore - Development simply involves merging the code, generating a unified migration file, and performing the migration
- Development projects can be on
Exploring problems is also a way for you to grow