jonny jonny - 4 months ago 89
MySQL Question

Force strict sql mode in django

I'm trying to force my django project to always use strict

. Is there another way than putting the following in
? It seems overly complicated.

def set_strict_sql_mode(sender, **kwargs):
from django.conf import settings
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.mysql':
from django.db import connection
cursor = connection.cursor()
cursor.execute('SET session sql_mode=traditional')

from django.core.signals import request_started


Actually asking proved to be a good rubber duck. Just after asking, I found the custom database OPTIONS one can supply in the DATABASES settings like this:

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {
            'sql_mode': 'traditional',

Hope it helps anyone!