Juanvulcano
Juanvulcano

Reputation: 1396

KeyError: u"Migration rango.0002_auto_20150905_0345 dependencies reference nonexistent parent node

I'm new with django and started messing up some things to see what would happened. The thing is I'm kinda screw up right now and would appreciate help.

I deleted some migrations manually and then run

manage.py squashmigrations app migration_name

And changed some migrations and then running the command again. The thing is now I'm facing this little bug. The last migration references another one as parent but it doesn't exist right now.

(kali)maker@localhost:~/Poker/tango_with_django_project$ sudo python manage.py migrate       
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
 File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 63, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 17, in __init__
self.loader = MigrationLoader(self.connection)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 48, in __init__
self.build_graph()
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 237, in build_graph
self.graph.add_dependency(migration, key, parent)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/graph.py", line 46, in add_dependency
"Migration %s dependencies reference nonexistent parent node %r" % (migration, parent)
KeyError: u"Migration rango.0002_auto_20150905_0345 dependencies reference nonexistent parent node (u'rango', u'0001_squashed_0004_auto_20150904_2325')"

Upvotes: 1

Views: 661

Answers (1)

gustav
gustav

Reputation: 197

in my case,

  1. Drop the db (pls backup/export the data)
  2. Delete *.pyc files in migrate folder
  3. Delete migration files in migrate folder, except for init.py
  4. Create new database with the same name
  5. Give privilige for user db
  6. Makemigrations
  7. Migrate
  8. Createsuperuser
  9. Runserver

And finally, it works.

Upvotes: 1

Related Questions