问题:django 使用pymysql 报如下错误:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
环境:python3.7 django2.2.1 pymysql0.9.3
原因:
Django连接MySQL时默认使用MySQLdb驱动,但MySQLdb不支持Python3,因此这里将MySQL驱动设置为pymysql
解决办法:
/usr/local/lib/python3.7/site-packages/django/db/backends/mysql
找到base.py文件,注释掉 base.py 中如下部分(35/36行)
if version < (1, 3, 3):
raise ImproperlyConfigured(“mysqlclient 1.3.3 or newer is required; you have %s” % Database.version)
找到operations.py文件(146行,),将decode改为encode
if query is not None:
query = query.decode(errors=‘replace’)
return query
#改为
if query is not None:
query = query.encode(errors=‘replace’)
return query