django2.2+pymysql0.9.3报错

最近看django视频时,由于视频较老,在配置数据库时出现以下错误:

报错环境 python=3.6,django=2.2,PyMySQL=0.9.3

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

 PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,Python2中则使用mysqldb。PyMySQL 目前版本最高是0.9.3,和django所需版本不符。

解决方案一:

使用低版本django如,django2.1.7。

解决方案二:

不使用 PyMySQL,使用mysqlclient。

解决方案三:

注释掉django/db/backends/mysql/base.py文件的第35、36行:

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

再次开启服务器,报错如下:

AttributeError: ‘str’ object has no attribute ‘decode’

定位报错位置:

if query is not None:
    query = query.encode(errors='replace')
return query

将'decode'改为'encode'即可。

扫描二维码关注公众号,回复: 6217882 查看本文章

猜你喜欢

转载自www.cnblogs.com/AngelLoveRZZZ/p/10854763.html