2011-08-21 116 views
0

有没有人看过这个错误?每当我尝试对我的特定模型执行查询时都会发生。直接查询数据库可以正常工作,而且其他模型不会发生这种情况。Django错误:AttributeError:'NoneType'对象没有属性'db'

MyModel.objects.get(name__iexact = 'an existent name') 

我相信这立即开始与南非数据库迁移后:

例如,它是由类似触发。我可以回滚迁移,但我不想让糟糕变得更糟,所以我先来这里。

  • 的Django 1.3
  • 的PostgreSQL 8.4.8
  • 的Python 2.7.0
  • IPython的0.10.2
  • 的Ubuntu 10.10 64位

任何想法?

ERROR: An unexpected error occurred while tokenizing input 
The following traceback may be corrupted or invalid 
The error message is: ('EOF in multi-line statement', (173, 0)) 

--------------------------------------------------------------------------- 
AttributeError       Traceback (most recent call last) 

/home/<path to python>/<ipython console> in <module>() 

/home/<path to python>/python2.7/site-packages/django/db/models/manager.pyc in get(self, *args, **kwargs) 
    130 
    131  def get(self, *args, **kwargs): 
--> 132   return self.get_query_set().get(*args, **kwargs) 
    133 
    134  def get_or_create(self, **kwargs): 

/home/<path to python>/python2.7/site-packages/django/db/models/query.pyc in get(self, *args, **kwargs) 
    342   if self.query.can_filter(): 
    343    clone = clone.order_by() 
--> 344   num = len(clone) 
    345   if num == 1: 
    346    return clone._result_cache[0] 

/home/<path to python>/python2.7/site-packages/django/db/models/query.pyc in __len__(self) 
    80     self._result_cache = list(self._iter) 
    81    else: 
---> 82     self._result_cache = list(self.iterator()) 
    83   elif self._iter: 
    84    self._result_cache.extend(self._iter) 

/home/<path to python>/python2.7/site-packages/django/db/models/query.pyc in iterator(self) 
    287 
    288     # Store the source database of the object 

--> 289     obj._state.db = db 
    290     # This object came from the database; it's not being added. 

    291     obj._state.adding = False 

AttributeError: 'NoneType' object has no attribute 'db' 
+2

如果你能够发布模型类,它可以帮助。这可能是问题所在。 –

+0

另外 - 值得发布'DATABASES'的设置值,因为这可能很重要:[docs](https://docs.djangoproject.com/en/dev/ref/settings/#databases) – danodonovan

回答

0

为自己踢这个,尤其是考虑到错误信息在回顾过程中有多明显。

我的迁移已经为模型添加了一个名为“_state”的新字段。该字段与上面query.pyc的第289行中引用的对象的_state属性相冲突。

新课程:Django模型中没有字段可以命名为“_state”。

这应该作为错误报告提交吗?

相关问题