Django中配置MariaDB数据库。配置文件如下:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database_name',
'PORT': 3306,
"HOST": '127.0.0.1',
'USER': 'username',
'PASSWORD': 'password',
'OPTIONS': {
'autocommit': True,
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
}
}
}
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
是解决警告:
WARNINGS:WARNINGS:
?: (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. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode