Django 迁移 - 依赖项引用不存在的父节点
Django Migrations - Dependencies reference nonexistent parent node
与普通迁移不同,这是一个不同的迁移。我删除了整个项目和数据库。使用了一个没有任何应用程序的基本 Django 项目。该错误始终指向我的旧迁移。为了确保我使用默认 SQL lite.
导致此错误的步骤:我尝试使用 add_to_class
和 contribute_to_class
方法将列添加到组模型。在这样做的过程中,我失去了迁移的轨迹。
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001E7701610D0>
Traceback (most recent call last):
File "E:\Python_365\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "E:\Python_365\lib\site-packages\django\core\management\commands\runserver.py", line 123, in inner_run
self.check_migrations()
File "E:\Python_365\lib\site-packages\django\core\management\base.py", line 427, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "E:\Python_365\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "E:\Python_365\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "E:\Python_365\lib\site-packages\django\db\migrations\loader.py", line 267, in build_graph
raise exc
File "E:\Python_365\lib\site-packages\django\db\migrations\loader.py", line 241, in build_graph
self.graph.validate_consistency()
File "E:\Python_365\lib\site-packages\django\db\migrations\graph.py", line 243, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "E:\Python_365\lib\site-packages\django\db\migrations\graph.py", line 243, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "E:\Python_365\lib\site-packages\django\db\migrations\graph.py", line 96, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration auth.0022_group_openid dependencies reference nonexistent parent node ('Task', '0003_auto_20181107_1811')
我不确定为什么 Django 仍然指我的迁移是其他哪个项目。这不让我也迁移我的其他项目,到处都是同样的错误。
听起来 0022_group_openid
迁移文件在 django 安装中,而不是在您的项目中,并且您正在为多个项目使用相同的安装。您可以手动删除额外的迁移文件。最好为每个项目使用不同的 virtualenv 并在那里安装 Django。
您可能需要查看 MIGRATION_MODULES
设置。它允许您将 django.contrib.auth
的迁移放入您的项目中,以便您可以将它们置于版本控制之下。
最后,向 Group
模型添加字段是不寻常的,因此您可能会遇到奇怪的行为。如果可能的话,我会尽量避免这样做。也许您可以将带有外键或一对一字段的单独模型添加到 Group
.
与普通迁移不同,这是一个不同的迁移。我删除了整个项目和数据库。使用了一个没有任何应用程序的基本 Django 项目。该错误始终指向我的旧迁移。为了确保我使用默认 SQL lite.
导致此错误的步骤:我尝试使用 add_to_class
和 contribute_to_class
方法将列添加到组模型。在这样做的过程中,我失去了迁移的轨迹。
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001E7701610D0>
Traceback (most recent call last):
File "E:\Python_365\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "E:\Python_365\lib\site-packages\django\core\management\commands\runserver.py", line 123, in inner_run
self.check_migrations()
File "E:\Python_365\lib\site-packages\django\core\management\base.py", line 427, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "E:\Python_365\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "E:\Python_365\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "E:\Python_365\lib\site-packages\django\db\migrations\loader.py", line 267, in build_graph
raise exc
File "E:\Python_365\lib\site-packages\django\db\migrations\loader.py", line 241, in build_graph
self.graph.validate_consistency()
File "E:\Python_365\lib\site-packages\django\db\migrations\graph.py", line 243, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "E:\Python_365\lib\site-packages\django\db\migrations\graph.py", line 243, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "E:\Python_365\lib\site-packages\django\db\migrations\graph.py", line 96, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration auth.0022_group_openid dependencies reference nonexistent parent node ('Task', '0003_auto_20181107_1811')
我不确定为什么 Django 仍然指我的迁移是其他哪个项目。这不让我也迁移我的其他项目,到处都是同样的错误。
听起来 0022_group_openid
迁移文件在 django 安装中,而不是在您的项目中,并且您正在为多个项目使用相同的安装。您可以手动删除额外的迁移文件。最好为每个项目使用不同的 virtualenv 并在那里安装 Django。
您可能需要查看 MIGRATION_MODULES
设置。它允许您将 django.contrib.auth
的迁移放入您的项目中,以便您可以将它们置于版本控制之下。
最后,向 Group
模型添加字段是不寻常的,因此您可能会遇到奇怪的行为。如果可能的话,我会尽量避免这样做。也许您可以将带有外键或一对一字段的单独模型添加到 Group
.