简体   繁体   English

django.db.migrations.exceptions.NodeNotFoundError

[英]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 的原因:

  1. pip uninstall django. pip卸载django。
  2. /Lib/site-packages, deleted django folder. /Lib/site-packages,删除 django 文件夹。
  3. Deleted all *.pyc files in my project.删除了我项目中的所有 *.pyc 文件。
  4. Deleted all pycache folders in my project.删除了我项目中的所有pycache文件夹。
  5. Cleared all migrations folders in my project (keep init .py).清除了我项目中的所有迁移文件夹(保留init .py)。
  6. pip install django==xxx pip 安装 django==xxx
  7. python manage.py migrate. python manage.py 迁移。
  8. python manage.py makemigrations <app_name>. python manage.py makemigrations <app_name>。
  9. python manage.py migrate. python manage.py 迁移。
  10. python manage.py runserver. python manage.py 运行服务器。 Now your problem will be solved.现在你的问题将得到解决。

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.

相关问题 Django 迁移 - django.db.migrations.exceptions.NodeNotFoundError - Django migrations - django.db.migrations.exceptions.NodeNotFoundError 删除迁移文件并获取 django.db.migrations.exceptions.NodeNotFoundError: - Deleting Migration Files and Getting django.db.migrations.exceptions.NodeNotFoundError: 我的项目中没有名为“帐户”的应用程序,但 django 仍然抛出 django.db.migrations.exceptions.NodeNotFoundError - No app named 'account' in my project but django still throws django.db.migrations.exceptions.NodeNotFoundError django.db.migrations.exceptions.NodeNotFoundError:运行“python manage.py migrate”时 - django.db.migrations.exceptions.NodeNotFoundError: upon running "python manage.py migrate" django.db.migrations.exceptions.NodeNotFoundError:迁移accounts.0001_initial依赖项引用不存在的父节点 - django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node 在命令提示符下运行服务器时出现 django.db.migrations.exceptions.NodeNotFoundError - django.db.migrations.exceptions.NodeNotFoundError when running the server in command prompt 删除我的数据库并尝试应用新的迁移后,我收到了这个错误,说 django.db.migrations.exceptions.NodeNotFoundError - After deleting my database and trying to apply a new migrations i get this errors that say django.db.migrations.exceptions.NodeNotFoundError 自定义 django 数据迁移创建记录 allauth.account EmailAddress model 返回错误 - django.db.migrations.exceptions.NodeNotFoundError: - Custom django data migration creating records allauth.account EmailAddress model returns error - django.db.migrations.exceptions.NodeNotFoundError: django.db.migrations.exceptions.NodeNotFoundError:迁移 app.0172_auto_20220603_1746 依赖 _auto_20220601_2313&#39;) - django.db.migrations.exceptions.NodeNotFoundError: Migration app.0172_auto_20220603_1746 dependencie _auto_20220601_2313') Django压缩了迁移:NodeNotFoundError - Django squashed migrations: NodeNotFoundError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM