Django: dependencies reference nonexistent parent node

PythonDjangoMigrate

Python Problem Overview


When I run the following command

python manage.py migrate

I receive this error from django so can't step forward in my practice:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
    self.build_graph()
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 241, in build_graph
    self.graph.add_dependency(migration, key, parent)
  File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/db/migrations/graph.py", line 42, in add_dependency
    raise KeyError("Migration %s dependencies reference nonexistent parent node %r" % (migration, parent))
KeyError: u"Migration testBolt.0001_initial dependencies reference nonexistent parent node (u'delivery_boy', u'0004_auto_20150221_2011')"

How do I solve this problem?

Python Solutions


Solution 1 - Python

Solution - 1

Remove pyc files from your migrations folder.

Solution - 2

Need to remove that reference from testBolt.0001_initial by editing migration file.

Solution - 3

  1. Remove the new changes from the models and run python manage.py migrate --fake

  2. Now again modify your models with new changes

  3. Run python manage.py makemigrations

  4. And then again run python manage.py migrate

Solution 2 - Python

In my case, I had the .py extension in the dependency module name, like this:

dependencies = [
    ('dashboard', '0003_auto_20181024_0603.py'),
    ('auth', '__latest__'),
    ('contenttypes', '__latest__'),
]

I removed the .py, changing it to this

    ('dashboard', '0003_auto_20181024_0603')

and that fixed it.

Solution 3 - Python

I had the same problem. In my case, because I played with migrations manually, I forgot to create __init__.py inside of migrations folder.

Solution 4 - Python

This works for me In your app migrations folder

  1. Delete all the files pyc in your app folder (except the __init__)

  2. Delete all the files in the migrations (except the __init__ )

  3. python manage.py makemigrations

  4. python manage.py migrate

  5. runserver

Solution 5 - Python

I had a similar case, running django in windows in a virtual env. In my case the missing dependency was 0001_initial - which was definitely there in the migration folder.

The 'solution' was to remove the pyc files and do another migrate attempt.

Solution 6 - Python

KeyError: u"Migration testBolt.0001_initial dependencies reference nonexistent parent node (u'delivery_boy', u'0004_auto_20150221_2011')"

Remove

> testBolt.0001_initial

then run migrate again

Solution 7 - Python

Here's how it worked for me:

  1. Deleted all the __pycache__ folders inside every app.
  2. Deleted all the files inside the migration folder except for __init.py__ inside each app folder.
  3. python manage.py makemigrations
  4. python manage.py migrate
  5. python manage.py runserver

Solution 8 - Python

Make sure that you have activated your virtual environment.

Solution 9 - Python

I tried NIKHIL's solutions with no luck. What did work for me was:

  • Removing my virtual environment
  • Deleting the migration __pycache__ folders
  • Deleting old migrations
  • Recreating my virtual environment
  • Running migrations

Solution 10 - Python

This worked for me:

  • Delete environment.
  • Crearte new environment with all dependencies

Solution 11 - Python

I had moved around my virtual environment folder.so I moved it back where it was, worked for me.

Solution 12 - Python

There could be some migration files remaining in the app when you tried the migrate command. First remove all migrations directories from all the modules. For other cases Nikhil Rane has covered it all.

Solution 13 - Python

I just uninstalled Django and reinstalled it:

pip3 uninstall Django

pip3 install Django

then migrated

Solution 14 - Python

Go to folder testBolt -> migrations and remove 0001_initial py and pyc files.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNIKHIL RANEView Question on Stackoverflow
Solution 1 - PythonNIKHIL RANEView Answer on Stackoverflow
Solution 2 - PythonChristian LongView Answer on Stackoverflow
Solution 3 - PythonTitanFighterView Answer on Stackoverflow
Solution 4 - PythonLê Hoàng VũView Answer on Stackoverflow
Solution 5 - Pythonjbos1234View Answer on Stackoverflow
Solution 6 - PythonHoangYellView Answer on Stackoverflow
Solution 7 - PythonSachinView Answer on Stackoverflow
Solution 8 - PythonDawn T CherianView Answer on Stackoverflow
Solution 9 - PythonProgrammingjoeView Answer on Stackoverflow
Solution 10 - PythonDiego Santa Cruz MendezúView Answer on Stackoverflow
Solution 11 - PythonClayton SibandaView Answer on Stackoverflow
Solution 12 - PythonVishvajit PathakView Answer on Stackoverflow
Solution 13 - Pythonshifna sherin vpView Answer on Stackoverflow
Solution 14 - PythonSreenath K MenonView Answer on Stackoverflow