Should I be adding the Django migration files in the .gitignore file?

Should I be adding the Django migration files in the .gitignore file?

I've recently been getting a lot of git issues due to migration conflicts and was wondering if I should be marking migration files as ignore.

If so, how would I go about adding all of the migrations that I have in my apps, and adding them to the .gitignore file?

Quoting from the Django migrations documentation:

The migration files for each app live in a “migrations” directory inside of that app, and are designed to be committed to, and distributed as part of, its codebase. You should be making them once on your development machine and then running the same migrations on your colleagues’ machines, your staging machines, and eventually your production machines.

If you follow this process, you shouldn't be getting any merge conflicts in the migration files.

To mitigate any issues you currently have, you should specify which repository or branch has the authoritative version of the migration files, and then use git's attribute mechanism to specify the merge strategy "ours" for these files. This will tell git to always ignore external changes to these files and prefer the local version.

From: stackoverflow.com/q/28035119

Back to homepage or read more recommendations: