Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARNINGS: ?: (mysql.W002) [closed]

Tags:

mysql

django

I'm new to django, just wanted to change to MySQL databases, but this warning keeps how up even though I have already added the code for it.

My setting.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "mysql_database",
        "USER": "root",
        "PASSWORD": "",
        "OPTION": {
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1",
            'charset': 'utf8mb4',
            "autocommit": True,
        }

    }
}

The warning

WARNINGS:
?: (mysql.W002) MariaDB Strict Mode is not set for database connection 'default'
        HINT: MariaDB's Strict Mode fixes many data integrity problems in MariaDB, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/3.1/ref/databases/#mysql-sql-mode

Have tried resetting and migrating a couple of times, and it didn't work.

like image 303
IcyHerrscher Avatar asked Jun 24 '26 04:06

IcyHerrscher


1 Answers

the error message you've got, provides you an element of solution. if you go to that link https://docs.djangoproject.com/en/3.1/ref/databases/#mysql-sql-mode you'll notice that it's OPTIONS (plural) and NOT OPTION (single):

If you need to customize the SQL mode, you can set the sql_mode variable like other MySQL options: either in a config file or with the entry 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" in the OPTIONS part of your database configuration in DATABASES.

and as good coding practices, dictionaries are usually kept in plural like DATABASES or OPTIONS.

like image 83
cizario Avatar answered Jun 26 '26 17:06

cizario