Django:依赖项引用不存在的父节点

Django: dependencies reference nonexistent parent node

当我运行下面的命令

python manage.py migrate

我从 django 收到这个错误,所以我无法继续练习:

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')"

如何解决这个问题?

转到文件夹 testBolt -> 迁移并删除 0001_initial py 和 pyc 文件。

我有一个类似的案例,运行 django in windows in a virtual env。在我的例子中,缺少的依赖项是 0001_initial - 它肯定存在于迁移文件夹中。

'solution' 是删除 pyc 文件并进行另一次迁移尝试。

确保您已激活虚拟环境。

解 - 1

从迁移文件夹中删除 pyc 个文件。

解 - 2

需要通过编辑迁移文件从 testBolt.0001_initial 中删除该引用。

解 - 3

  1. 从模型中删除新更改 运行 python manage.py migrate --fake

  2. 现在再次用新的更改修改您的模型

  3. 运行 python manage.py makemigrations

  4. 然后又是运行python manage.py migrate

我遇到了同样的问题。就我而言,因为我手动进行了迁移,所以我忘记在 migrations 文件夹中创建 __init__.py

当您尝试迁移命令时,应用程序中可能会残留一些迁移文件。首先从所有模块中删除所有 migrations 目录。对于其他情况,Nikhil Rane 已全部介绍。

我尝试了 NIKHIL 的解决方案,但没有成功。对我有用的是:

  • 正在删除我的虚拟环境
  • 正在删除迁移 __pycache__ 个文件夹
  • 删除旧迁移
  • 重新创建我的虚拟环境
  • 运行 迁移

在我的例子中,我在依赖模块名称中有 .py 扩展名,如下所示:

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

我删除了 .py,将其更改为这个

    ('dashboard', '0003_auto_20181024_0603')

然后修复了它。

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

删除

testBolt.0001_initial

然后运行再次迁移

这对我有用 在您的应用程序迁移文件夹中

  1. 删除你的应用文件夹中的所有pyc文件(__init__除外)
  2. 删除迁移中的所有文件(__init__除外)

  3. python manage.py makemigrations

  4. python manage.py migrate
  5. runserver

我在我的虚拟环境中四处移动folder.so我把它移回原处,对我有用。

这对我有用:

  • 删除环境。
  • 创建包含所有依赖项的新环境

以下是它对我的作用:

  1. 删除了每个应用程序中的所有 __pycache__ 个文件夹。
  2. 删除了迁移文件夹中的所有文件,每个应用程序文件夹中的 __init.py__ 除外。
  3. python manage.py makemigrations
  4. python manage.py migrate
  5. python manage.py runserver

我刚刚卸载了 Django 并重新安装了它:

pip3 uninstall Django

pip3 install Django

然后迁移