数据迁移时报错——django.db.migrations.exceptions.NodeNotFoundError: Migration apitest.0001_initial dependencies reference nonexistent parent node ('product', '0001_initial')

时间:2021-02-23
本文章向大家介绍数据迁移时报错——django.db.migrations.exceptions.NodeNotFoundError: Migration apitest.0001_initial dependencies reference nonexistent parent node ('product', '0001_initial'),主要包括数据迁移时报错——django.db.migrations.exceptions.NodeNotFoundError: Migration apitest.0001_initial dependencies reference nonexistent parent node ('product', '0001_initial')使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

执行python manage.py makemigrations时出现以下错误

D:\autotestplat>python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "D:\Program Files\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "D:\Program Files\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Program Files\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\Program Files\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "D:\Program Files\Python\Python37-32\lib\site-packages\django\core\management\commands\makemigrations.py", line 78, in handle
    loader = MigrationLoader(None, ignore_no_migrations=True)
  File "D:\Program Files\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
    self.build_graph()
  File "D:\Program Files\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 267, in build_graph
    raise exc
  File "D:\Program Files\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 241, in build_graph
    self.graph.validate_consistency()
  File "D:\Program Files\Python\Python37-32\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 "D:\Program Files\Python\Python37-32\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 "D:\Program Files\Python\Python37-32\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 apitest.0001_initial dependencies reference nonexistent parent node ('product', '0001_initial')

问题原因:由于'product' 应用下的'0001_initial'文件不存在,而在 apitest应用下的0001_initial 文件中引用了product中的迁移记录

问题解决:删除 apitest->migrations下的0001_initial .py文件,再重新执行命令

原文地址:https://www.cnblogs.com/mian-1122/p/14437079.html