Django query is case sensitive after moving to MariaDB

I have a Django project that can perform a query using a person's name as show in the attached code.

def get_queryset(self):
    query = self.request.GET.get('query')

    if query:
        query = " ".join(query.split())

        if query.isdigit():
            qs = Patient.objects.filter(Q(full_name__contains=query) | Q(patient_id__contains=query)).order_by('patient_id')
        else:
            qs = Patient.objects.filter(Q(full_name__contains=query) | Q(patient_id__contains=query)).order_by(Lower('full_name'))
    else:
        qs = Patient.objects.order_by(Lower('full_name'))

    return qs

This works in a case insensitive manner in SQLite3, which is what I want.

I recently moved the project to MariaDB and now the query is case sensitive. I have checked to collation on the database, table, column, ... and it is set to utf8mb3_general_ci which by my understanding should result in a case insensitive search.

Interestingly enough, doing the interactive query:

select full_name from patients_patient where full_name like 'ana maria%';

results in a case insensitive search. Any ideas why the query in my code is case sensitive and how to make it case insensitive?

Вернуться на верх