How to manage version controlled Django migrations as a team?

Viewed 530

We're a small team of developers working on a version-controlled Django 3 project. We are worried about utilizing migrations and the possibility of overwriting one another's migration files.

Options we've considered:

  • Using the --name / -n option of makemigrations to have a naming convention, but that seems cumbersome
  • Django documentation mentions tools for version control, but I don't see much on the specifics on it.

How do other teams handle this?

1 Answers

Using version control (git, etc.) will solve your problem.

Just make sure the developers work on a branch rather than directly on master. This way, the migrations will be visible, and if there's a conflict, git will let you know when you try to merge to your master branch. It's even more obvious if you're using GitHub as you can see the conflicts in the UI for the pull request.

The only problem you will have here is if two migrations are generated in the same app in two PRs. The one that gets merged into master last will cause a problem as there will be multiple leaf nodes, but this can be solved easily with ./manage.py makemigrations --merge, and ideally you should run ./manage.py makemigrations --check to see if there are problems before merging stuff - in continuous integration, for exaple.

Related