gpt4 book ai didi

django - [django] 错误 : contenttypes couldn't be reset

转载 作者:行者123 更新时间:2023-12-02 05:09:21 25 4
gpt4 key购买 nike

我在加载夹具之前重置了内容类型(请参阅 Problems with contenttypes when loading a fixture in Django)。

但是无法重置内容类型:

...project_dir > manage.py reset contenttypes

You have requested a database reset. This will IRREVERSIBLY DESTROYany data for the "contenttypes" application in the database"my_database". Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

Error: Error: contenttypes couldn't be reset. Possible reasons:

  • The database isn't running or isn't configured correctly.
  • At least one of the database tables doesn't exist.
  • The SQL was invalid.

Hint: Look at the output of 'django-admin.py sqlreset contenttypes'.That's the SQL this command wasn't able to run.

The full error: (1217, 'Cannot delete or update a parent row: aforeign key cons traint fails')

任何帮助将不胜感激。谢谢!

最佳答案

关于您发布的问题还有另一个 answer - 使用 natural keys用于固定装置。

错误“无法删除或更新父行:外键约束失败”意味着无法删除内容类型行,因为有另一个对象指向该行。例如。如果有任何非空白的通用外键关系就是这种情况。

如果您确实需要重置内容类型应用程序,您可以获得为此所需的 SQL 命令并将其更改为使用 CASCADE 语句。然而,这是危险的,因为它不仅会删除内容类型,还会删除其他表中指向内容类型的行。

所以我建议使用自然键重新创建固定装置。

关于django - [django] 错误 : contenttypes couldn't be reset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7389132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com