Ole*_*nko 4 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': 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
Run Code Online (Sandbox Code Playgroud)
首先,我在互联网上检查了类似的问题.这个似乎非常相关:http://code.djangoproject.com/ticket/5996,因为我的数据有很多非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$
Run Code Online (Sandbox Code Playgroud)
最后一条评论出错
<DeserializedObject: qwert2000's profile>
Run Code Online (Sandbox Code Playgroud)
问题安装夹具'/Users/oleg/probs.json':Traceback(最近一次调用最后一次):文件"/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py ",第154行,句柄obj.save()文件"/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py",第163行,保存模型.Model.save_base (self.object,raw = True)文件"/opt/local/lib/python2.5/site-packages/django/db/models/base.py",第495行,在save_base结果= manager._insert(values, return_id = update_pk)文件"/opt/local/lib/python2.5/site-packages/django/db/models/manager.py",第177行,在_insert中返回insert_query(self.model,values,**kwargs)在insert_query返回查询中的文件"/opt/local/lib/python2.5/site-packages/django/db/models/query.py",第1087行.execute_sql(return_id)文件"/opt/local/lib/python2.5/site-packages/django/db/models/sql/subqueries.py",第320行,在execute_sql cursor = super(InsertQuery,self).execute_sql(无)文件"/opt/local/lib/python2.5/site-packages/django/db/models/sql/query.py",第2369行,在execute_sql中为cursor.execute(sql,params)文件"/ opt/local/lib/python2.5/site-packages/django/db/backends/util.py",第19行,在执行中返回self.cursor.execute(sql,params)编程错误:无法适应params)文件"/opt/local/lib/python2.5/site-packages/django/db/backends/util.py",第19行,在执行返回self.cursor.execute(sql,params)编程错误:可以'适应params)文件"/opt/local/lib/python2.5/site-packages/django/db/backends/util.py",第19行,在执行返回self.cursor.execute(sql,params)编程错误:可以'适应
该can't adapt错误是由psycopg2当它接收的数据类型,它不知道如何转化为SQL语句中的值为止.例如,如果您不小心传递了一个列表,例如,对于一个应该是整数的值,psycopg2会引发这个不能适应的错误.
该faq.txt附带psycopg2的源代码分发这样解释文件:
为什么
!cursor.execute()提出异常无法适应?Psycopg通过查看对象类来转换SQL字符串表示形式的Python对象.当您尝试将没有为其类注册的适配器的对象作为查询参数传递时,会引发异常.请参阅:ref:
adapting-new-typesfor information.
在找到有问题的值时,你可能最好的第一步是在完全冗长的模式下运行loaddata:python manage.py loaddata --verbosity = 2 /Users/oleg/probs.json
好吧,我希望loaddata冗长可行,我不必承认我从来没有找到一种用django的loaddata调试自适应错误的优雅方法.在过去,我已经在django的loaddata函数中插入了print语句,以便在发生错误时可以看到反序列化的值.我编辑过django/core/management/loaddata.py.外观obj.save()的handle()功能.我希望这个忏悔鼓励某人分享更好的解决方案:-)
| 归档时间: |
|
| 查看次数: |
1864 次 |
| 最近记录: |