强制 sql_mode 为“STRICT_TRANS_TABLES”仍然收到警告 Django
Posted
技术标签:
【中文标题】强制 sql_mode 为“STRICT_TRANS_TABLES”仍然收到警告 Django【英文标题】:Forcing sql_mode to "STRICT_TRANS_TABLES" still got warning Django 【发布时间】:2019-11-16 15:45:06 【问题描述】:我正在使用Django 2.1.3
,pymysql 0.9.2
,mysql 5.7
,python3.5
sql_mode in mysql:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
db setting in django:
DATABASES =
'default':
'ENGINE': 'django.db.backends.mysql',
...,
'OPTIONS':
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
'charset': 'utf8mb4'
,
我总是收到这样的警告:
/venv3.5/lib/python3.5/site-packages/pymysql/cursors.py:170: Warning: (3135, "'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.")
result = self._query(query)
/venv3.5/lib/python3.5/site-packages/pymysql/cursors.py:170: Warning: (3090, "Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.")
result = self._query(query)
为什么我会收到上述警告?
非常欢迎任何评论。非常感谢。
【问题讨论】:
【参考方案1】:试试:
DATABASES =
'default':
'ENGINE': 'django.db.backends.mysql',
...,
'OPTIONS':
'init_command': "SET sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER'",
'charset': 'utf8mb4'
,
你也可以看到warnings — Warning control。
【讨论】:
以上是关于强制 sql_mode 为“STRICT_TRANS_TABLES”仍然收到警告 Django的主要内容,如果未能解决你的问题,请参考以下文章