Skip to content Skip to sidebar Skip to footer

Django - MySQL Strict Mode With Database Url In Settings

I'm using a database URL string in my settings like: DATABASES = { 'default': 'mysql://root:@localhost:3306/mydb' } When I migrate I get this warning: MySQL Strict Mode is not

Solution 1:

You could update your settings afterwards:

DATABASES['default']['OPTIONS'] = {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"}

Solution 2:

I think this one will help you. you can pass the options as a query string in the URL

DATABASES = {
    'default': dj_database_url.config(default="mssql://USER:PASSWORD@HOST:PORT/NAME?init_command=SET sql_mode='STRICT_TRANS_TABLES'&charset=utf8mb4", conn_max_age=500)
}

Solution 3:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'USER': 'root',
        'PASSWORD': 'test123',
        'OPTIONS': {
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
            'charset': 'utf8mb4',
        }
    }
}

Try to give init_command of database options in settings.py If want know more refer the docs django_mysql.W001: Strict Mode


Post a Comment for "Django - MySQL Strict Mode With Database Url In Settings"