Files deleted by Django Migrations

Asked

Viewed 1,521 times

2

I’m having a constant problem. As I am working with several branchs in a project, sometimes I go back in an old branch, bring updated branch to the old one so I don’t have to keep creating old bank Migration. Only every time of the problem with Migrations. Sometimes it gives an absurd error and I delete everything, Migrations, base and recomeco. It works, only then the files of Migration are different. So when I will migrate the error because this missing file or dependency.

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

In my case, that’s the problem:

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 for the file:

0010_auto_20170605_1809

However you do not have this file. It has probably been deleted or something like that. I could try switching manually to the last file, the 0002_auto_20170621_1721. However, he has the validation in the bank, I think is not ideal.

I tried to do zero migrate, but the error keeps giving. I did a --fake (which I’ve been told is pork) and nothing.

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

1 answer

0


Problems with Migrations are very common in the Django universe, as I have seen reports that in complex scenarios some teams prefer to create mechanisms to disable migrations. After some time of "suffering" and a lot of 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 the history for all apps, the example below clears the history of the core name 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 that commands in a file and run it every time I deploy, output copy for staging or staging to the location.

  • If you keep the production bank always synchronized with the work (integration continues) this is no problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.