I'm using Django 1.7 with migrations, and I'm not sure about what is the best practice, I should add the migrations files to my repository, or this is a bad idea?

- 10,058
- 6
- 42
- 52

- 44
- 5
-
What do you mean by add? In your git repository? yes! – abrunet Nov 18 '15 at 15:45
-
Related: [Why there is need to push django migrations to version control system](http://stackoverflow.com/q/32376092/1324033) – Sayse Nov 18 '15 at 15:47
-
migrations in version control allows you to run them in production. If you don't save them in version control, you lose track of database schema. – Allen Fernandes Nov 18 '15 at 18:29
-
I have published an article on writing scalable Django apps and it also includes migration best practices, failure cases etc. https://digiqt.com/blog/django-best-practices-for-scalable-apps.html – Hitul May 23 '21 at 05:00
2 Answers
you should create migration files locally, migrate locally and test it, and then commit the files to version control. django docs says:
The reason that there are separate commands to make and apply migrations is because you’ll commit migrations to your version control system and ship them with your app; they not only make your development easier, they’re also useable by other developers and in production.
if multiple developers are working on the same project, they dont have to create the migrate files, they just do migrate
and everything is paradise.

- 36,596
- 57
- 175
- 260
Yes, they must be versioned. If you are alone, it's not problem because you add the right database schema because each time you edit a model, you run makemigrations
and migrate
.
But how your colleagues can have the database schema that corresponds to the new models that you committed if they can't run your migrations too.
Commit your migrations, to allow your colleagues to run migrate
and have the same database schema.

- 10,058
- 6
- 42
- 52