django2.2/mysql ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3

报错环境 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.

  

解决方法:
Django链接MySQL时默认使用MySQLdb驱动,但MySQLdb不支持Python3,所以这里将MySQL驱动设置为pymysql,使用 pip install pymysql 进行安装,而后在工程文件__init__.py添加如下代码便可。python

#安装pymysqlmysql

pip install pymysql

#__init__.py
import pymysql
pymysql.install_as_MySQLdb()

第一种:
django降到2.1.4版本就OK了sql

 

第二种(仍使用django 2.2版本):django

一、#找到Python环境下 django包,并进入到backends下的mysql文件夹
cd /opt/anaconda3/envs/envAGC_Mini/lib/python3.6/site-packages/django/db/backends/mysqlbash


二、# 找到base.py文件,注释掉 base.py 中以下部分(35/36行)
if version < (1, 3, 3):
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)

此时仍会会报错,报错信息以下:ui

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

#找到operations.py文件(46行,版本不一样行数不一样哈~自个儿find一下),将decode改成encode.net

if query is not None:
query = query.decode(errors='replace')
return query
#改成
if query is not None:
query = query.encode(errors='replace')
return query

 
原文:https://blog.csdn.net/weixin_33127753/article/details/89100552

code

相关文章
相关标签/搜索