Python Django:依赖项引用不存在的父节点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28668351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django: dependencies reference nonexistent parent node
提问by NIKHIL RANE
When I run the following command
当我运行以下命令时
python manage.py migrate
I receive this error from django so can't step forward in my practice:
我从 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')"
How do I solve this problem?
我该如何解决这个问题?
采纳答案by NIKHIL RANE
Solution - 1
解决方案 - 1
Remove pycfiles from your migrations folder.
pyc从迁移文件夹中删除文件。
Solution - 2
解决方案 - 2
Need to remove that reference from testBolt.0001_initialby editing migration file.
需要testBolt.0001_initial通过编辑迁移文件来删除该引用。
Solution - 3
解决方案 - 3
Remove the new changes from the models and run
python manage.py migrate --fakeNow again modify your models with new changes
Run
python manage.py makemigrationsAnd then again run
python manage.py migrate
从模型中删除新更改并运行
python manage.py migrate --fake现在再次使用新的更改修改您的模型
跑
python manage.py makemigrations然后再次运行
python manage.py migrate
回答by Sreenath K Menon
Go to folder testBolt -> migrations and remove 0001_initial py and pyc files.
转到文件夹 testBolt -> migrations 并删除 0001_initial py 和 pyc 文件。
回答by Jeremias B
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.
我有一个类似的案例,在虚拟环境中的 Windows 中运行 django。在我的情况下,缺少的依赖项是 0001_initial - 它肯定在迁移文件夹中。
The 'solution' was to remove the pyc files and do another migrate attempt.
“解决方案”是删除 pyc 文件并进行另一次迁移尝试。
回答by Dawn T Cherian
Make sure that you have activated your virtual environment.
确保您已激活虚拟环境。
回答by TitanFighter
I had the same problem. In my case, because I played with migrations manually, I forgot to create __init__.pyinside of migrationsfolder.
我有同样的问题。就我而言,因为我手动进行了迁移,所以我忘记__init__.py在migrations文件夹内创建。
回答by Vishvajit Pathak
There could be some migration files remaining in the app when you tried the migrate command. First remove all migrationsdirectories from all the modules. For other cases Nikhil Rane has covered it all.
当您尝试 migrate 命令时,应用程序中可能会保留一些迁移文件。首先migrations从所有模块中删除所有目录。对于其他情况,Nikhil Rane 已经涵盖了所有内容。
回答by Programmingjoe
I tried NIKHIL's solutions with no luck. What did work for me was:
我尝试了 NIKHIL 的解决方案,但没有运气。对我有用的是:
- Removing my virtual environment
- Deleting the migration
__pycache__folders - Deleting old migrations
- Recreating my virtual environment
- Running migrations
- 删除我的虚拟环境
- 删除迁移
__pycache__文件夹 - 删除旧迁移
- 重新创建我的虚拟环境
- 运行迁移
回答by Christian Long
In my case, I had the .pyextension in the dependency module name, like this:
就我而言,我.py在依赖模块名称中有扩展名,如下所示:
dependencies = [
('dashboard', '0003_auto_20181024_0603.py'),
('auth', '__latest__'),
('contenttypes', '__latest__'),
]
I removed the .py, changing it to this
我删除了.py,将其更改为
('dashboard', '0003_auto_20181024_0603')
and that fixed it.
并修复了它。
回答by HoangYell
KeyError: u"Migration testBolt.0001_initial dependencies reference nonexistent parent node (u'delivery_boy', u'0004_auto_20150221_2011')"
Remove
消除
testBolt.0001_initial
testBolt.0001_initial
then run migrate again
然后再次运行迁移
回答by Lê Hoàng V?
This works for me In your app migrations folder
这对我有用 在您的应用程序迁移文件夹中
- Delete all the files pyc in your app folder (except the
__init__) Delete all the files in the migrations (except the
__init__)python manage.py makemigrationspython manage.py migraterunserver
- 删除应用程序文件夹中的所有文件 pyc(除了
__init__) 删除迁移中的所有文件(除了
__init__)python manage.py makemigrationspython manage.py migraterunserver

