之前有没有人见过这个错误?每当我尝试对我的特定模型执行查询时,它就会出现。直接查询数据库工作正常,其他模型不会发生这种情况。
例如,它由以下内容触发:
MyModel.objects.get(name__iexact = 'an existent name')
我相信这是在与South进行数据库迁移后立即开始的。我可以回滚迁移,但我不想让情况更糟,所以我先来这里。
有什么想法吗?
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'
答案 0 :(得分:0)
为这一点做好准备,特别是考虑到错误信息在回顾过程中有多么明显。
我的迁移为模型添加了一个名为“_state”的新字段。此字段与上面query.pyc的第289行引用的对象的_state属性冲突。
新课程:在Django模型上没有字段可以命名为“_state”。
这应该作为错误报告提交吗?