Should I add Django migration files to a .gitignore file?

Should I add Django migration files to a .gitignore file?

I recently got a lot of git problems due to migration conflicts and wondered if marking migration files should be ignored.

If so, how can I add all the migrations that I have in my applications and add them to the .gitignore file?

+52
git python django
Jan 19 '15 at 23:10
source share
6 answers

Quote from the Django migration documentation:

The migration files for each application are located in the "migrations" directory inside this application and are intended to be bound to its code base and distributed as part of it. You have to do them once on your development machine, and then perform the same migrations on the computers of your colleagues, on your station machines and, ultimately, on your production machines.

If you follow this process, you should not receive merge conflicts in the migration files.

To fix any problems that you have, you must specify which repository or branch has an authoritarian version of the migration files, and then use the git attribute mechanism to specify the merge strategy "ours" for these files. This means that git always ignores the external changes of these files and prefers the local version.

+54
Jan 19 '15 at 23:22
source share

No.

I have done this many times, and I cannot, in my life, find a case where we need migrations to the repo.

As I can see, the final entry is the models.py schema. If I change the change and someone pulls it, everything will be correct when they start makemigrations and migrate . There is no need to determine which β€œours” strategy for migration.

If we need a rollback, we return the models and migrate. All is well, no problem, ever.

There is no complaint that the field already exists, etc.

I wonder if someone can give me a specific case where it would be useful for me to combine other developer migration files before I can get started. I know that the documents say that I should, so I guess so. But I have never met even one.

Is anyone

+4
Feb 19 '16 at 17:13
source share

You can follow the process described below.

You can run makemigrations locally and this will create a migration file. Commit this new migration file for the repo.

In my opinion, you should not run makemigrations in production at all. You can run migrate during production, and you will see that the migration is applied from the migration file that you checked from the local one. This way you can avoid all conflicts.

+2
Mar 02 '17 at 7:05
source share

It looks like you need to set up your git workflow, instead of ignoring conflicts.

Ideally, each new function is developed in a different branch and combined with a pull request.

PR cannot be combined if there is a conflict, so it needs to combine its function in order to resolve the conflict, including migrations.

+1
May 11 '16 at 10:01
source share

I can’t imagine why you will have conflicts if you don’t edit the migration in any way? Usually this fails - if someone skips some intermediate commits, they will not be updated from the correct version, and their copy of the database will be corrupted.

The process I'm doing is pretty simple - whenever you change the models for the application, you also make the transfer, and then the transfer does not change - if you need something else then change the model and perform a new migration along with the changes .

In projects with new projects, you can often remove the migration and start from scratch with the transfer 0001_ at release, but if you have production code, you cannot (although you can squander the migration down one).

+1
May 27 '16 at 13:23
source share

A commonly used solution is that before anything is merged into master, the developer must pull any remote changes. If there is a conflict in the migration versions, it should rename its local migration (the remote was launched by other developers and, possibly, during the production process), to N + 1.

It might be good at design time to just not make migrations (don't add ignore, but just don't add them). But as soon as you move on to production, you will need them to synchronize the circuit with model changes.

Then you need to edit the file and change the dependencies to the latest deleted version.

This works for porting Django, as well as other similar applications (sqlalchemy + alembic, RoR, etc.).

0
Jul 26 '17 at 0:28
source share



All Articles