從轉儲數據安裝燈具時出現奇怪的錯誤。我正在使用psycopg2和django1.1.1django:從postgres數據庫導入數據時無法修改錯誤
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
首先我檢查了互聯網上的類似問題。這一個似乎非常有關: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$
錯誤
<DeserializedObject: qwert2000's profile>
問題安裝夾具 '/Users/oleg/probs.json':回溯(最近通話最後一個): 文件「/ 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行,保存爲 models.Model.save_base(self.object,raw = True) File」/ op t/local/lib/python2.5/site-packages/django/db/models/base.py「,第495行,在save_base result = manager._insert(values,return_id = update_pk) 」/ opt/local /lib/python2.5/site-packages/django/db/models/manager.py「,第177行,在_insert中 return insert_query(self.model,values,** kwargs) 」/ opt/local/lib /python2.5/site-packages/django/db/models/query.py「,第1087行,在insert_query中 return query.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(None) 文件」/opt/local/lib/python2.5/site-packages /django/db/models/sql/query.py「,第2369行,在execute_sql中 cursor.execute(sql,par ams) 文件「/opt/local/lib/python2.5/site-packages/django/db/backends/util.py」,第19行,執行 return self.cursor.execute(sql,params) ProgrammingError :不能適應
MMMM ....所以,我該怎麼辦?我只需要將數據導入數據庫...也許有另一種方式做到這一點? – 2010-06-16 18:10:39
如果您採用與我相同的低級方法,請在系統上打開django的副本,並在loaddata.py模塊的obj.save()之前添加一條打印語句,以查看您要傳出的錯誤數據的系統。問題將成爲堆棧跟蹤之前的最後一條打印語句。 – 2010-06-16 19:41:32
是的。看我最近的編輯。但我不明白這個問題是怎麼出現的...爲什麼 DoesNotExist:用戶匹配查詢不存在。 – 2010-06-16 23:38:57