2011-09-12 57 views
3

我重置之前加载夹具(参照Problems with contenttypes when loading a fixture in Django)CONTENTTYPES。[django的]错误:CONTENTTYPES不能复位

但CONTENTTYPES不能复位:

...project_dir > manage.py reset contenttypes

You have requested a database reset. This will IRREVERSIBLY DESTROY any 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: a foreign key cons traint fails')

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

+0

可以在命令中输入'django-admin.py sqlreset contenttypes'和看到的错误是有什么呢? –

+0

对此有何见解?你有没有设法解决这个问题? –

回答

0

在这个问题你贴有另一answer - 使用natural keys的灯具。

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

如果你真的需要重置内容类型的应用程序,你可以得到所需要这个SQL命令并改变其使用CASCADE声明。但是,这是危险,因为它不仅会删除内容类型,还会删除其他表中指向内容类型的行。

所以我建议重新创建使用自然键灯具。