在django测试期间加载灯具时的IntegrityError [英] IntegrityError when loading fixture during django testing

查看:124
本文介绍了在django测试期间加载灯具时的IntegrityError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 安装fixture'db_dump.json时遇到的问题':追溯(最近的最后一次通话):
文件/usr/lib/python2.6/site-packages/django/core/management/commands/loaddata.py,第174行,处理
obj.save(using = using)
文件/usr/lib/python2.6/site-packages/django/core/serializers/base.py,第165行,保存
模型。 Model.save_base(self.object,using = using,raw = True)
文件/usr/lib/python2.6/site-packages/django/db/models/base.py,第526行, save_base
rows = manager.using(using).filter(pk = pk_val)._ update(values)
文件/usr/lib/python2.6/site-packages/django/db/models/ query.py,第491行,在_update
中,返回query.get_compiler(self.db).execute_sql(无)
文件/usr/lib/python2.6/site-packages/django/db /models/sql/compiler.py,行869,在execute_sql
cursor = super(SQLUpdateCompiler,self).execute_sql(resu lt_type)
文件/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py,行735,在execute_sql
cursor.execute(sql,params )
文件/usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py,第234行,执行
return Database.Cursor.execute(self ,query,params)
IntegrityError:列app_label,模型不是唯一的

一个sqlite3后端。



更新:使用自然键在这里没有任何区别。



意思是,为什么会发生?

解决方案

显然,不必要的陷阱之一是导出固定装置时必须排除内容类型。 (感谢#django上的信息获取信息)。



要排除内容类型,请使用 -e 选项运行dumpdata命令。

  $。/ manage.py dumpdata -e contenttypes> initial_data.json 


I'm loading a fixture created with dumpdata, and getting the following exception:

Problem installing fixture 'db_dump.json': Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/django/core/management/commands/loaddata.py", line 174, in handle
    obj.save(using=using)
  File "/usr/lib/python2.6/site-packages/django/core/serializers/base.py", line 165, in save
    models.Model.save_base(self.object, using=using, raw=True)
  File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 526, in save_base
    rows = manager.using(using).filter(pk=pk_val)._update(values)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 491, in _update
    return query.get_compiler(self.db).execute_sql(None)
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 869, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py", line 234, in execute
    return Database.Cursor.execute(self, query, params)
IntegrityError: columns app_label, model are not unique

This is with a sqlite3 backend.

Update: Using natural keys doesn't make a difference here.

What does it mean, and why is it happening?

解决方案

Apparently one of the traps for the unwary is that one must exclude contenttypes when exporting fixtures. (Thanks to subsume on #django for the information).

To exclude content types use the -e option when running the dumpdata command.

$./manage.py dumpdata -e contenttypes > initial_data.json

这篇关于在django测试期间加载灯具时的IntegrityError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆