Google app engine 为什么查询uu isnull=True会导致数据库错误?
当我使用Google app engine 为什么查询uu isnull=True会导致数据库错误?,google-app-engine,django-nonrel,Google App Engine,Django Nonrel,当我使用\uu isnull=True对ForeignKey字段进行筛选时,会引发此异常: DatabaseError: This query is not supported by the database. 但是,只要没有其他不等式过滤器(我期望),ForeignKey上的\uu isnull=False就可以工作。而\uu isnull=True适用于其他字段类型 那么为什么在ForeignKey上不起作用呢?似乎DBIndexer试图使其工作如下所示: 但Djangoolbox中有一
\uu isnull=True
对ForeignKey字段进行筛选时,会引发此异常:
DatabaseError: This query is not supported by the database.
但是,只要没有其他不等式过滤器(我期望),ForeignKey上的\uu isnull=False
就可以工作。而\uu isnull=True
适用于其他字段类型
那么为什么在ForeignKey上不起作用呢?似乎DBIndexer
试图使其工作如下所示:
但Djangoolbox中有一个例外:
File "/Users//Documents/workspace/-gae-dev/src/django/db/models/query.py", line 107, in _result_iter
self._fill_cache()
File "/Users//Documents/workspace/-gae-dev/src/django/db/models/query.py", line 774, in _fill_cache
self._result_cache.append(self._iter.next())
File "/Users//Documents/workspace/-gae-dev/src/django/db/models/query.py", line 275, in iterator
for row in compiler.results_iter():
File "/Users//Documents/workspace/-gae-dev/src/djangotoolbox/db/basecompiler.py", line 337, in results_iter
results = self.build_query(fields).fetch(
File "/Users//Documents/workspace/-gae-dev/src/djangotoolbox/db/basecompiler.py", line 428, in build_query
self.check_query()
File "/Users//Documents/workspace/-gae-dev/src/djangotoolbox/db/basecompiler.py", line 409, in check_query
raise DatabaseError("This query is not supported by the database.")
我确实在djangoappengine中遇到了以下注释掉的测试用例,我想知道它是否指的是同一个问题
def test_is_null(self):
self.assertEquals(FieldsWithOptionsModel.objects.filter(
floating_point__isnull=True).count(), 0)
FieldsWithOptionsModel(
integer=5.4, email='shinra.tensai@sixpaths.com',
time=datetime.datetime.now().time()).save()
self.assertEquals(FieldsWithOptionsModel.objects.filter(
floating_point__isnull=True).count(), 1)
# XXX: These filters will not work because of a Django bug.
# self.assertEquals(FieldsWithOptionsModel.objects.filter(
# foreign_key=None).count(), 1)
# (it uses left outer joins if checked against isnull)
# self.assertEquals(FieldsWithOptionsModel.objects.filter(
# foreign_key__isnull=True).count(), 1)
Alex Burgel在NonRel项目上的发言让我直截了当: NonRel/dbindexer项目修复了这个查询(由于这个Django错误,这个查询无法正常工作:)。要设置dbindexer,请执行以下操作:
- 当然,可以将其添加到已安装的应用程序中
- 同样在settings.py中,设置数据库['default]['ENGINE']='dbindexer'
- 同样在settings.py中,将DBINDEXER_后端设置为使用FKNullFix。例如: