Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is need to push django migrations to version control system

This is a common practice that people working on django project usually push migrations to the version control system along with other code.

My question is why this practice is so common? Why not just push the updated models and everyone generate migrations locally. This approach can reduce the effort for resolving migrations conflicts too.

like image 284
Ishtiaq Avatar asked Sep 03 '15 12:09

Ishtiaq


People also ask

Why do we need Django migration?

Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They're designed to be mostly automatic, but you'll need to know when to make migrations, when to run them, and the common problems you might run into.

Should I commit Django migration files?

It is important though to commit migration files! If a conflict arises, Django might even help you solve those conflicts ;) That's the right answer. An operational versioning system workflow seems to be implicit in the django documentation but it's fundamental.

What happens if I delete migrations Django?

Deleting migration files means losing your history. This historical info is recorded in the django_migrations table in your database. if you delete migration files, you will get dependency errors. So Don't try to lose your history by deleting your migration files.

What is difference between migrate and migration in Django?

So the difference between makemigrations and migrate is this: makemigrations auto generates migration files containing changes that need to be applied to the database, but doesn't actually change anyhting in your database. migrate will make the actual modifications to your database, based on the migration files.


1 Answers

If you didn't commit them to a VCS then what would happen is people would make potentially conflicting changes to the model.

When finally ready to deploy, you would still need django to make new migrations that would then merge everybodys changes together. And this just creates an additional unnecessary step that can introduce bugs.

You also are assuming everybody will always be able to work on an up to date version of the code which isn't always possible when you start working on branches that are not ready to be merged into mainline.

like image 50
Sayse Avatar answered Nov 14 '22 21:11

Sayse