Deleted Files Django Migrations

1

I'm having a constant problem. As I'm working with several branches in a project, sometimes I go back in an old branch, I bring branch updated to old so I do not have to be creating old bank migration. So every time of the problem with migrations. Sometimes it's an absurd mistake and I delete everything, the migrations, the base and recomecho. This works, so the migration files are different. So when I'm going to migrate the error because it's missing a file or dependency.

I would like to understand the process that I have to do to avoid or solve these problems. Remembering that I have an environment in production, that even if it is not available to the user, this type of problem can probably happen.

In my case the problem is this:

django.db.migrations.exceptions.NodeNotFoundError: Migration comunidade.0011_auto_20170608_1556 dependencies reference nonexistent parent node ('comunidade', '0010_auto_20170605_1809')

When I enter the file, it has a dependency on the file:

0010_auto_20170605_1809

But you do not have this file. For it was probably deleted or something. I could try manually switching to the last file, 0002_auto_20170621_1721 . However, it has validation in the bank, I think it is not the ideal.

I tried to make migrate zero, but the error keeps on giving. I made a --fake (they already told me it's pork) and nothing.

I need some hint. I'm using Django 1.10 and Python 3.4

    
asked by anonymous 29.06.2017 / 23:22

2 answers

-1

Problems with migrations are very common in the django universe, I've seen reports that in complex scenarios some teams prefer to create mechanisms to disable migrations. After some time of "suffering" and much research in the intenet, I ended up creating a script to "reset" the migrations, I will reproduce the steps below (my environment is linux):

1) Clear history for all apps, the example below clears the history of the core app.

python manage.py makemigrations
python manage.py migrate --fake core zero

2) Remove the migration files:

find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc"  -delete

3) Create the initial migrations:

$ python manage.py makemigrations
$ python manage.py migrate --fake-initial

Now give a showmigrations and see that everything is ok.

My strategy:
I put those commands in a file and execute it every time I do a deploy, a production copy for staging or staging for the site.

    
30.06.2017 / 02:44
-1

The safest solution I found now was to play the migrations of the parent branch on the disorganized branch. I'll explain in detail my case:

The case that occurs most of this type of problem, is when I change from branch of versions more updated to older. Even with the different migrations, my database goes crazy to sync. Finished giving these problems.

Deleting migrations is not a good idea when you need to do a database version rollback. Anyway, in my case the migrations is very important to maintain.

The solution I found was to get the migrations from the branch DEV and bring it to branch XX-50 . I first deleted all migrations from the XX-50 branch and then added the saved files to the temporary folder of the DEV branch .

After that, I gave a migrate, and django asked to do a makemigrations - merge. I did, he asked to confirm some changes and everything else and soon after I was able to migrate without problems.

This completely solved my problem. I have all the migration versions and I was able to bring the version of the updated DEV branch to an outdated branch without deleting my database .

The annoying thing was having to keep going back and forth in the branches to check the mistakes they made. First I solved the migrations of an app. Then I had to stay checking and in my case I had to bring migrations from 3 different apps. It would be great a script to automate this.

    
30.06.2017 / 19:56