django:can';从postgres数据库导入数据时出错

django:can';从postgres数据库导入数据时出错,django,postgresql,psycopg2,Django,Postgresql,Psycopg2,我在从转储的数据安装夹具时遇到了奇怪的错误。我使用的是psycopg2和django1.1.1 silver:probsbox oleg$ python manage.py loaddata /Users/oleg/probs.json Installing json fixture '/Users/oleg/probs' from '/Users/oleg/probs'. Problem installing fixture '/Users/oleg/probs.json': Traceba

我在从转储的数据安装夹具时遇到了奇怪的错误。我使用的是psycopg2和django1.1.1

silver:probsbox oleg$ python manage.py loaddata /Users/oleg/probs.json 
Installing json fixture '/Users/oleg/probs' from '/Users/oleg/probs'.
Problem installing fixture '/Users/oleg/probs.json': Traceback (most recent call last):
  File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 153, in handle
    obj.save()
  File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 163, in save
    models.Model.save_base(self.object, raw=True)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 495, in save_base
    result = manager._insert(values, return_id=update_pk)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/manager.py", line 177, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 1087, in insert_query
    return query.execute_sql(return_id)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/subqueries.py", line 320, in execute_sql
    cursor = super(InsertQuery, self).execute_sql(None)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 2369, in execute_sql
    cursor.execute(sql, params)
  File "/opt/local/lib/python2.5/site-packages/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
ProgrammingError: can't adapt
首先,我在网上查过类似的问题。这一个似乎非常相关:,因为我的数据有许多非ASCII符号

但实际上我已经检查了我的django安装,它在那里没有问题

你能告诉我怎么了吗

====

按照第一个答案的建议添加打印声明后,继续调查。日志看起来是这样的:

silver:probsbox oleg$ python manage.py loaddata /Users/oleg/probs.json 
Installing json fixture '/Users/oleg/probs' from '/Users/oleg/probs'.
<DeserializedObject: Novice>
<DeserializedObject: Junior>
<DeserializedObject: Chess enthusiast>
<DeserializedObject: Experienced player >
<DeserializedObject: Smart player>
Problem installing fixture '/Users/oleg/probs.json': Traceback (most recent call last):
  File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 153, in handle
    print obj
  File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 155, in __repr__
    return "<DeserializedObject: %s>" % smart_str(self.object)
  File "/opt/local/lib/python2.5/site-packages/django/utils/encoding.py", line 107, in smart_str
    return str(s)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 335, in __str__
    return force_unicode(self).encode('utf-8')
  File "/opt/local/lib/python2.5/site-packages/django/utils/encoding.py", line 71, in force_unicode
    s = unicode(s)
  File "/Users/oleg/Sites/probsbox/registration/models.py", line 58, in __unicode__
    return u"%s's profile" %(self.user.username)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/fields/related.py", line 257, in __get__
    rel_obj = QuerySet(self.field.rel.to).get(**params)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 305, in get
    % self.model._meta.object_name)
DoesNotExist: User matching query does not exist.

silver:probsbox oleg$ 
silver:probsbox oleg$python manage.py loaddata/Users/oleg/probs.json
从'/Users/oleg/probs'安装json装置'/Users/oleg/probs'。
安装fixture“/Users/oleg/probs.json”时出现问题:回溯(最近一次调用last):
文件“/opt/local/lib/python2.5/site packages/django/core/management/commands/loaddata.py”,第153行,在handle中
打印对象
文件“/opt/local/lib/python2.5/site packages/django/core/serializers/base.py”,第155行,在__
返回“%smart\u str(self.object)
文件“/opt/local/lib/python2.5/site packages/django/utils/encoding.py”,第107行,在smart_str中
返回str(s)
文件“/opt/local/lib/python2.5/site packages/django/db/models/base.py”,第335行,在__
返回力_unicode(自)。编码('utf-8')
文件“/opt/local/lib/python2.5/site packages/django/utils/encoding.py”,第71行,有效
s=unicode(s)
文件“/Users/oleg/Sites/probsbox/registration/models.py”,第58行,采用unicode编码__
返回u“%s”的配置文件%(self.user.username)
文件“/opt/local/lib/python2.5/site packages/django/db/models/fields/related.py”,第257行,在__
rel_obj=QuerySet(self.field.rel.to).get(**参数)
文件“/opt/local/lib/python2.5/site packages/django/db/models/query.py”,get中第305行
%self.model.\u meta.object\u name)
DoesNotExist:用户匹配查询不存在。
银币:probsbox oleg美元
最后一条评论的错误

<DeserializedObject: qwert2000's profile>

当psycopg2接收到不知道如何转换为SQL语句的值的数据类型时,会引发
无法调整
错误。例如,如果您意外地传递了一个列表,例如,对于一个假定为整数的值,psycopg2将引发此无法自适应错误

psycopg2源发行版附带的
faq.txt
文档对此进行了如下解释:

silver:probsbox oleg$ python manage.py loaddata /Users/oleg/probs.json 
Installing json fixture '/Users/oleg/probs' from '/Users/oleg/probs'.
<DeserializedObject: Novice>
<DeserializedObject: Junior>
<DeserializedObject: Chess enthusiast>
<DeserializedObject: Experienced player >
<DeserializedObject: Smart player>
Problem installing fixture '/Users/oleg/probs.json': Traceback (most recent call last):
  File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 153, in handle
    print obj
  File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 155, in __repr__
    return "<DeserializedObject: %s>" % smart_str(self.object)
  File "/opt/local/lib/python2.5/site-packages/django/utils/encoding.py", line 107, in smart_str
    return str(s)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 335, in __str__
    return force_unicode(self).encode('utf-8')
  File "/opt/local/lib/python2.5/site-packages/django/utils/encoding.py", line 71, in force_unicode
    s = unicode(s)
  File "/Users/oleg/Sites/probsbox/registration/models.py", line 58, in __unicode__
    return u"%s's profile" %(self.user.username)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/fields/related.py", line 257, in __get__
    rel_obj = QuerySet(self.field.rel.to).get(**params)
  File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 305, in get
    % self.model._meta.object_name)
DoesNotExist: User matching query does not exist.

silver:probsbox oleg$ 
为什么
!cursor.execute()
引发异常无法适应

Psycopg通过查看 在对象类中。尝试通过时引发异常 没有为其注册适配器的对象作为查询参数 它的等级。有关信息,请参阅:ref:
调整新类型

在查找有问题的值时,最好的第一步是在完全详细的模式下运行loaddata:python manage.py loaddata--verbosity=2/Users/oleg/probs.json


嗯,我希望loaddata的详细性能够起作用,而且我不必承认我从未找到一种优雅的方法来调试django的loaddata的自适应错误。过去,我在django的loaddata函数中插入了print语句,以便在发生错误时可以看到反序列化的值。我编辑了
django/core/management/loaddata.py
。查看
handle()
函数中的
obj.save()
。我希望这个自白能启发大家分享一个更好的解决方案:-)

好的,我结束了从数据库复制转储文件,并在没有python的情况下在本地恢复它…

mmmm。。。。那我该怎么办?我只需要将数据导入数据库。。。也许还有另一种方法?如果您采用与我相同的低级方法,请在系统上打开django的副本,并在loaddata.py模块中的obj.save()之前添加一条print语句,以查看从系统中获取的错误数据。问题将是堆栈跟踪之前的最后一个打印语句。是的。查看我的最新编辑。但我不明白这个问题是怎么出现的。。。Why DoesNotExist:用户匹配查询不存在。mmmm。。。。但我并没有为用户应用程序制作fixture,所以通常我的数据库中并没有用户。。。让我们先尝试导入用户不,这没有帮助。错误不存在,已消失。。。但无法适应。。。