转储数据python manage.py dumpdata --format json --indent 4 --exclude auth.permission --exclude contenttypes > app/fixtures/app_test_data.json
运行 python manage.py 测试应用程序,出现以下错误:
IntegrityError: Problem installing fixtures: The row in table 'django_admin_log' with primary key '517' has an invalid foreign key: django_admin_log.content_type_id contains a value '28' that does not have a corresponding value in django_content_type.id.
有什么想法吗?我在使用 dumpdata/Django 的测试运行程序时遇到了很多类似的问题。
最佳答案
如果:
- 您只是想在知道此问题之前从生成的 json 中恢复信息
- 您不关心管理日志的数据
- 您(或其他人)使用以下命令生成了不包括 auth.permission 和 contenttypes 的 json:
python manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json
您可以使用文本编辑器恢复 json 中捕获的信息,打开文件并删除与 admin.logentry 模型关联的元素。
这对我有用!
关于Django 测试提示 Fixture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19415558/