学习就是不断的踩坑,填坑
直入主题:
本机环境:win8 py3.5.1 Django2.0
Django 连接mysql数据库
cmd中使用python3 manage.py migrate命令,报warn
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.djangoprojec
t.com/en/dev/ref/databases/#mysql-sql-mode
解决办法:settings.py文件夹加入DATABASES['OPTIONS']['init_command'] = "SET sql_mode='STRICT_TRANS_TABLES'"
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_test',
'USER':'root',
'PASSWORD':'',
'HOST':'localhost',
'PORT':'3306',
#下面是新加入的
'OPTIONS':{
'init_command':"SET sql_mode='STRICT_TRANS_TABLES'",
'charset':'utf8mb4',
},
}
}
网友评论