git and django migrations: ignore the migrations files

Viewed 9818

Should I keep django migrations files in a git repository? In a developers team, how they manages their database changes.

For example, Tom has made changes in their models, and ran makemigrations and migrate, his database now has changed, as well his migrations files, keeping his migration story.

Meantime, Bob has made changes too. He has his migration files that are about another models, He ran makemigrations and migrate commands, and his db changed.

Tom and Bob are working in the same app, so, They share the same migrations files. And the same db too.

So, what will happen when Bob push their code to git repo, and later Tom pull or fetch it from git repo? The migrations files will be mixed and their stories will be broken. Also, what about with the db itself, if it is a sqlite file, should I keep it in git repo?

4 Answers

https://gist.github.com/mhipo1364/a55da230e1ec80bfab70e9650637bb15/revisions

Re-Generate Migration

To merge exist migration files into one file:

  • Remove django_migration records table (manually)
  • Remove all migration files
  • run python manage.py migrate --fake command
  • run python manage.py makemigrations command
  • run python manage.py migrate --fake-initial command
  • run python manage.py migrate contenttypes command
  • and finally, for chacking if everything is just fine, run python manage.py migrate command
Related