标签:lin inux code class mysql 官方 ocs encode driver
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
Django - installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3
标签:lin inux code class mysql 官方 ocs encode driver
原文地址:https://www.cnblogs.com/allen2333/p/11754161.html