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'
如果你能夠發佈模型類,它可以幫助。這可能是問題所在。 –
另外 - 值得發佈'DATABASES'的設置值,因爲這可能很重要:[docs](https://docs.djangoproject.com/en/dev/ref/settings/#databases) – danodonovan