【发布时间】:2020-12-07 22:49:42
【问题描述】:
当我尝试使用 model.objects.filter(mybooleanfield=True) 时出现此错误
('42000', "[42000] [Microsoft] [SQL Server Native Client 11.0] [SQL Server] A non-Boolean expression was specified in a context where a condition was expected, near 'mybooleanfield'. (4145) (SQLExecDirectW) ")
但这只有在使用带有BooleanField 的过滤器时才会发生,如果我使用PositiveIntegerField, CharField, DateTimeField or TextField,则过滤器没有问题。我认为这可能适用于我使用的版本
Python 3.9.0
Django 3.1.3
Pyodbc 4.0.30
Django-mssql-backend 2.8.1
我需要使用我的BooleanField 作为条件。有人知道为什么会这样吗?
【问题讨论】:
-
你能分享一个导致问题的行的例子吗?或您的代码示例。还要给出定义 BooleanField 的行。
标签: django pyodbc django-mssql-backend