[英]django.db.migrations.exceptions.NodeNotFoundError
When i run makemigrations
command, i got this error:当我运行
makemigrations
命令时,出现此错误:
Traceback (most recent call last):
...
django.db.migrations.exceptions.NodeNotFoundError: Migration products.0002_auto_20160618_1143 dependencies reference nonexistent parent node (u'products', u'0001_initial')
If you open the migration file products.0002_auto_20160618_1143
you will see a section called dependencies:如果您打开迁移文件
products.0002_auto_20160618_1143
您将看到一个名为依赖项的部分:
dependencies = [("products", "0001_initial")]
Which will look like that.看起来像那样。 This line tell Django that the current file depends on that file.
这一行告诉 Django 当前文件依赖于该文件。 A file that given that error message isn't there.
给出该错误消息的文件不存在。 You can try commenting out that line and running the command again.
您可以尝试注释掉该行并再次运行该命令。 Be aware that if one file is missing it's possible many are missing so you should reconcile your dependencies with what files you actually have.
请注意,如果缺少一个文件,则可能缺少多个文件,因此您应该将依赖项与您实际拥有的文件进行协调。
DISCLAIMER: If this is a production DB messing around with migration files can be dangerous if you don't know what you are doing.免责声明:如果这是一个生产数据库,如果您不知道自己在做什么,那么弄乱迁移文件可能会很危险。 You should test this on a staging or dev server first (preferably one that has a snapshot you can restore to).
您应该首先在登台服务器或开发服务器上对此进行测试(最好是具有可以恢复到的快照的服务器)。
如果你在你的数据库中没有任何严重的数据,你可以简单地重置您的迁移,因为它已经解释这里。
If it not solve after reseting the migrations, follow the following steps: Apparently django kept migration files within it's own module folder.如果重置迁移后仍未解决,请按照以下步骤操作: 显然 django 将迁移文件保存在它自己的模块文件夹中。 This is why you need to flush the django:
这就是您需要刷新 Django 的原因:
Delete the file product.0002_auto_20160618_1143 migration file.删除文件 product.0002_auto_20160618_1143 迁移文件。
and again run the following commands:并再次运行以下命令:
1. python manage.py makemigrations . 1. python manage.py makemigrations 。
2. python manage.py migrate . 2. python manage.py migrate 。
If you have dangling dependency to 0002_auto_20160618_1143
in a file created by makemigrations
command and file does not exist then, please remove this reference from that file.如果你已经晃来晃去的依赖于
0002_auto_20160618_1143
由创建的文件makemigrations
命令和文件不存在的话,请删除该文件此引用。 Remember to to remove migration from django_migrations
table as well.请记住也要从
django_migrations
表中删除迁移。 That fixed my issue那解决了我的问题
dependencies = [
('workspace', '0002_auto_20160618_1143'),
('datasets', '0001_initial'),
]
If you recently deleted an app and trying the migrations.如果您最近删除了一个应用程序并尝试迁移。 Then better : Delete the file product.0002_auto_20160618_1143 migration file.
那么更好:删除文件 product.0002_auto_20160618_1143 迁移文件。 and again run the following commands:
并再次运行以下命令:
1.python manage.py makemigrations. 1.python manage.py makemigrations。 2.python manage.py migrate.
2.python manage.py 迁移。 delete
删除
Also you can follow the most rated comment.您也可以关注评分最高的评论。 But commentate the newly deleted app name from dependencies.
但是从依赖项中注释新删除的应用程序名称。 Don't commentate the whole dependencies.
不要评论整个依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.