Django 测试提示 Fixture

标签 django django-models django-testing django-fixtures

转储数据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 的测试运行程序时遇到了很多类似的问题。

最佳答案

如果:

  1. 您只是想在知道此问题之前从生成的 json 中恢复信息
  2. 您不关心管理日志的数据
  3. 您(或其他人)使用以下命令生成了不包括 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/

相关文章:

Django:有没有办法从单元测试中计算 SQL 查询?

python - Django REST 框架 : "This field is required." with required=False and unique_together

django - 管理面板上更好的 Django 日期时间过滤器

python - Django 模型方法 - create_or_update

python - 在 Django 中使用相关对象批量创建对象的有效方法是什么?

python - Django一对一模型中的更新/编辑功能

除非指定了应用程序和特定的测试方法,否则 Django 不会使用 manage.py test 运行测试

python - 在 Django 中验证 Google ID token

django - 模型中的用户 OneToOneField

django - 如何在 `APIClient`中的 `django rest_framework test` header 中添加身份验证 token