I'm currently upgrading a Django project from 2.2 to 3.2, but I'm getting an error from SQL Server when trying to load a View:
ProgrammingError at /my/django/url ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]An expression of non-boolean type specified in a context where a condition is expected, near ')'. (4145) (SQLExecDirectW)")
I have a queryset that is filtering on a Boolean Field ('islead'), the queryset contains .filter(islead=True)
, however when I load the View, I can see from Django debug toolbar that the SQL query doesn't include "WHERE islead = TRUE", it only has "WHERE islead" with no condition.
This works fine in Django 2.2. Here is an extract of my code:
models.py:
class LecturerCourseYear(models.Model):
ay = models.IntegerField(db_column='AY', primary_key=True)
code = models.CharField(db_column='Code', max_length=12)
lecturer = models.ForeignKey('Lecturers', models.DO_NOTHING, db_column='lecturer', max_length=12)
islead = models.BooleanField(db_column='IsLead')
views.py:
def edit_course(request, code, ay):
primary_lecturer_response = LecturerCourseYear.objects.filter(ay=ay, code=code, islead=True).order_by('position')
initialData = {'primary_lecturer': ','.join([lecturer.lecturer.id for lecturer in primary_lecturer_response]),
form = editCourseForm(initial=initialData)
return render(request, 'courses/edit-course.html', {'form': form})