Site Overlay

django使用mysql报严格模式的警告

django数据移植的时候,报以下警告时:

ARNINGS:
?: (mysql.W002) 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.

解决办法

在settings.py中数据库配置中加入'OPTIONS',如下:

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

参考:
http://django-mysql.readthedocs.io/en/latest/checks.html

Leave a Reply

Your email address will not be published. Required fields are marked *