2013-10-15 72 views
0

我試圖更新我的Django模型中的int字段之一。`嘗試保存模型Django 1.5時出現`namedtuple_as_object`錯誤

但在更新此字段時出現以下錯誤。

(這是使用IPython的python manage.py shell

# this is what I m trying to do 
>> a = download.objects.get(id=1) 
>> a.url = "" 
>> a.save() # raises an error 

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
/usr/local/lib/python2.7/dist-packages/django/core/management/commands/shell.pyc in <module>() 
----> 1 a.save() 

/usr/local/lib/python2.7/dist-packages/django/db/models/base.pyc in save(self, force_insert, force_update, using, update_fields) 
    544 
    545   self.save_base(using=using, force_insert=force_insert, 
--> 546      force_update=force_update, update_fields=update_fields) 
    547  save.alters_data = True 
    548 

/usr/local/lib/python2.7/dist-packages/django/db/models/base.pyc in save_base(self, raw, cls, origin, force_insert, force_update, using, update_fields) 
    624       values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks] 
    625       if values: 
--> 626        rows = manager.using(using).filter(pk=pk_val)._update(values) 
    627        if force_update and not rows: 
    628         raise DatabaseError("Forced update did not affect any rows.") 

/usr/local/lib/python2.7/dist-packages/django/db/models/query.pyc in _update(self, values) 
    603   query.add_update_fields(values) 
    604   self._result_cache = None 
--> 605   return query.get_compiler(self.db).execute_sql(None) 
    606  _update.alters_data = True 
    607 

/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.pyc in execute_sql(self, result_type) 
    1012   related queries are not available. 
    1013   """ 
-> 1014   cursor = super(SQLUpdateCompiler, self).execute_sql(result_type) 
    1015   rows = cursor and cursor.rowcount or 0 
    1016   is_empty = cursor is None 

/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.pyc in execute_sql(self, result_type) 
    828   """ 
    829   try: 
--> 830    sql, params = self.as_sql() 
    831    if not sql: 
    832     raise EmptyResultSet 

/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.pyc in as_sql(self) 
    977     val = val.prepare_database_save(field) 
    978    else: 
--> 979     val = field.get_db_prep_save(val, connection=self.connection) 
    980 
    981    # Getting the placeholder for the field. 

/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.pyc in get_db_prep_save(self, value, connection) 
    302   """ 
    303   return self.get_db_prep_value(value, connection=connection, 
--> 304          prepared=False) 
    305 
    306  def get_prep_lookup(self, lookup_type, value): 

/usr/local/lib/python2.7/dist-packages/jsonfield/fields.pyc in get_db_prep_value(self, value, connection, prepared) 
    47   if isinstance(value, basestring): 
    48    return value 
---> 49   return json.dumps(value, **self.dump_kwargs) 
    50 
    51  def value_to_string(self, obj): 

/usr/lib/python2.7/dist-packages/simplejson/__init__.pyc in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, encoding, default, use_decimal, namedtuple_as_object, tuple_as_array, **kw) 
    294   namedtuple_as_object=namedtuple_as_object, 
    295   tuple_as_array=tuple_as_array, 
--> 296   **kw).encode(obj) 
    297 
    298 

TypeError: __init__() got an unexpected keyword argument 'namedtuple_as_object' 

是否有人可以建議我,這是怎麼回事錯在這裏?

回答

6

您在該模型中有一個json字段,並且您遇到了與simplejsondocumented in Django 1.5 release notes as a potential issue有關的問題。

您需要卸載simplejsonpip uninstall simplejson如果您通過pip安裝它)。這樣,Django將使用Python的內置版本,但沒有這些兼容性問題。

+0

謝謝!這對我有效。 –

相關問題