【转载】报错:django.core.exceptions.ImproperlyConfigured: mysqlclient

使用python3.7+django2.2+pymysql时遇到这个错误:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2 1。 别急,这主要是django2.2内部的一个版本限制在作怪

处理方案

报错1django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3. 原因:django2.2和pymysql版本不匹配。mysqldb不支持python3.

解决办法: \python安装路径\Python37\Lib\site-packages\django\db\backends\mysql(python安装目录,或者虚拟环境目录)打开base.py,注释掉以下内容:

if version < (1, 3, 13):
    raise ImproperlyConfigured(‘mysqlclient 1.3.13 or newer is required; you have %s.’ % Database.version)    

报错2:File “\python安装目录(python虚拟目录)\Python37\lib\site-packages\django\db\backends\mysql\operations.py”, line 146, in last_executed_query    query = query.decode(errors=‘replace’)    AttributeError: ‘str’ object has no attribute ‘decode’    解决办法: 打开此文件把146行的decode修改为encode

原文地址:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2