当我运行以下命令
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')"
我该如何解决这个问题?
解决方案 - 1
从迁移文件夹中删除pyc文件。
解决方案 - 2
需要通过编辑迁移文件从testBolt.0001_initial中删除该引用。
解决方案 - 3
python manage.py migrate --fake
python manage.py makemigrations
python manage.py migrate
转到文件夹testBolt - >迁移并删除0001_initial py和pyc文件。
我有一个类似的案例,在虚拟环境中在Windows中运行django。在我的情况下,缺少的依赖是0001_initial - 这肯定在迁移文件夹中。
'解决方案'是删除pyc文件并进行另一次迁移尝试。
我有同样的问题。在我的情况下,因为我手动使用迁移,我忘了在__init__.py
文件夹中创建migrations
。
在我的例子中,我在依赖模块名称中有.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
然后再次运行迁移
尝试迁移命令时,应用程序中可能还有一些迁移文件。首先从所有模块中删除所有migrations
目录。对于其他情况,Nikhil Rane已经涵盖了所有这些。
我试过NIKHIL的解决方案没有运气。对我有用的是:
__pycache__
文件夹这适用于我在您的应用迁移文件夹中
__init__
除外)__init__
除外)python manage.py makemigrations
python manage.py migrate
runserver