I am developing an E-commerce website using Python 3.6. I made a fresh installation of Django 2.0.6 and connected it to a MySQL database (on the localhost) by defining the Database variables in settings.py
as below:
DATABASES = {
'default': {
'ENGINE' : 'django.db.backends.mysql',
'NAME' : 'moda',
'OPTIONS' : {
'init_command' : "SET sql_mode='STRICT_TRANS_TABLES'",
'init_command' : 'SET innodb_strict_mode=1',
'charset' : 'utf8mb4',
},
'USER' : 'root',
'PASSWORD' : '',
'SERVER' : 'localhost',
'PORT' : '3306'
}
}
and after running the python manage.py check
command using cmd, I am getting the following warning:
(django_mysql.W001) MySQL Strict Mode is not set for database connection 'default'
HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://django-mysql.readthedocs.io/en/latest/checks.html#django-mysql-w001-strict-mode
I even used ' init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
, and I'm still getting the warning!
I would be so grateful if some expert could show me the right way to fix this!
Thanks Guys.
Author of django-mysql
here.
You have two 'init_command'
keys in the dictionary, so only the second one will be in there after parsing - Python just silently handles duplicates like this. Hint: use flake8
to lint your source code, as it detects this and warns you.
Additionally, the two SET
commands can be combined, giving:
...
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1",
'charset': 'utf8mb4',
},
...
HTH!