pymysql版本0.9.3,django2.2需要>=1.3.13的版本

2019年4月26日 问题:
pymysql版本0.9.3,django2.2需要>=1.3.13的版本

报错信息:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

原因: 使用了pymysql驱动,官方文档说需要mysqlclient驱动1.3.13或更高的版本 官方文档贴图

解决办法: 更换mysql驱动,使用mysqlclient驱动 pip install mysqlclient/<projectname>/<projectname>/__init__.py里将

import pymysql
pymysql.install_as_MySQLdb()

替换成

import MySQLdb

完美解决

评论 2

  • 还有其它方法 找到你Django目录下的base.py文件 注释掉下面2句:

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

    然后再进行数据库迁移操作。

    如果还有问题,比如出现了以下问题: File "D:\Program Files\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'

    那就打开operations.py文件,146行中的decode改为encode。