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

django2.2连接mysql5.7遇到这个报错,参考大佬的博客解决问题,下面记录下自己的操作供日后参考。本篇博客参考了大佬的博客https://blog.youkuaiyun.com/weixin_33127753/article/details/89100552

我是T型人小付,一位坚持终身学习的互联网从业者。喜欢我的博客欢迎在csdn上关注我,如果有问题欢迎在底下的评论区交流,谢谢。

操作环境

  • python 3.7.1
  • Django 2.2.10
  • mysql 5.7
  • pymysql 0.9.3

错误现象

Pycharm连接到了mysql,进行迁移操作

(django) [fuhx@testmachine HelloDjango]$ python manage.py migrate

出现下列报错

File "/home/fuhx/python_projects/django/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
   raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3

报错解决

打开报错中提到的base.py文件,把35,36行注释掉

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

再次尝试迁移,又出现下面的报错

File "/home/fuhx/python_projects/django/lib/python3.7/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'

python3中的str类型通过encode方法变为bytes类型,bytes类型通过decode方法变为str类型
decode改为encode,如下

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

问题得到解决

验证解决

再次进行迁移,没有任何报错。刷新Pycharm中的mysql数据库,发现表已经生成了,说明迁移成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值