Django - installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3

匿名 (未验证) 提交于 2019-12-02 22:06:11

Deepin Linux 15.11
Django 2.2
pymysql0.9.3


因为用pymysql替换了默认的mysqlclient,Django官方推荐的数据库API driver是mysqlclient。

https://docs.djangoproject.com/en/2.2/ref/databases/#mysql-db-api-drivers

不要用pymysql。用mysqlclient。
安装方法:https://github.com/PyMySQL/mysqlclient-python#install


2.1 配置文件的目录中_init_.py中有如下代码

import pymysql  pymysql.install_as_MySQLdb()    # 这是一个hack,为了在Djano中替代默认的mysqlclient。mysqlclient官方描述:This is a fork of MySQLdb1

2.2 点进去install_as_MySQLdb
找到version_info变量,改成

version_info = (1, 3, 13, "final", 0)

2.3 改变django.db.backends.mysql.operations.py的一行代码

query = query.decode(errors='replace') -> query = query.encode(errors='replace')

原因:mysqlclient returns bytes object, PyMySQL returns str object
参考:https://github.com/PyMySQL/PyMySQL/issues/790#issuecomment-484201388


https://stackoverflow.com/a/55954355/5955399

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!