Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Best way to merge migrations conflicts

Tags:

I'm currently working on a dev branch and I will need to merge it to master one day. I have up to 20 migrations files on my dev branch and about the same number on master at the moment. I needed to make migrations on both branches which will result in migrations having the same prefix,

(ex 0003_auto)

In other words, if you have migrations files generated by makemigrations with the same prefix, what is the best/secure way of handling this.

Here are two ways I have figured myself (maybe entirely wrong):

  1. Deleting all migrations files, merge the code and then running a fresh makemigrations and migrate which will result in only one migration file.

  2. Using the --merge flag to let django make the merge:

    makemigrations --merge
    

Now, knowing all this I'd like to know what is the best way of handling this. In general, what should I use that will correctly merge conflicts and get me a fresh version of my project with every model updates.

EDIT

I think providing a step by step solution would be ideal for me and future users since there exists tons of informations on the subject but not one seems to be concise and clear.

like image 215
scharette Avatar asked Nov 03 '17 13:11

scharette


1 Answers

From the Django docs:

Because migrations are stored in version control, you’ll occasionally come across situations where you and another developer have both committed a migration to the same app at the same time, resulting in two migrations with the same number.

Don’t worry - the numbers are just there for developers’ reference, Django just cares that each migration has a different name [emphasis added].

like image 148
ostergaard Avatar answered Oct 19 '22 02:10

ostergaard