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

今天在linux系统部署程序时报错,django2.2 mysql 8.0 错误信息如下:

python manage.py makemigrations

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

首先想到的是,升级mysqlclient版本:

pip install --upgrade mysqlclient
Collecting mysqlclient
  Downloading https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz (85kB)
     |████████████████████████████████| 92kB 47kB/s 
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.4.2.post1

完了执行python manage.py makemigrations 还是报错!

通过google找到的解决方案如下:

Django连接MySQL时默认使用MySQLdb驱动,但MySQLdb不支持Python3,因此这里将MySQL驱动设置为pymysql,使用 pip install pymysql 进行安装,然后在工程文件init.py添加以下代码即可。

#安装pymysql
pip install pymysql

#__init__.py
import pymysql
pymysql.install_as_MySQLdb()
  1. 把django版本降到2.1.4即可
  2. 继续使用2.2版本
#找到Python环境下 django包,并进入到backends下的mysql文件夹
cd /home/aaa/.pyenv/versions/getRivalData/lib/python3.6/site-packages/django/db/backends/mysql/
# 找到base.py文件,注释掉 base.py 中如下部分
if version 

再次执行还会报错: AttributeError: ‘str’ object has no attribute ‘decode’ 解决办法:

#找到operations.py文件,将decode改为encode
if query is not None:
    query = query.decode(errors='replace')
return query
#改为
if query is not None:
    query = query.encode(errors='replace')
return query

最后,问题解决,我们就可以愉快的使用django了

继续阅读
Vultr 新用户注册就送100$
shunzi
  • 本文由 发表于 2019-06-1811:02:47
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
deepin linux 15.11系统安装 BLOG

deepin linux 15.11系统安装

Deepin 15.11系统安装 window系统实在是太难用了,用了那么多linux系统,发现deepin系统真的是太好用了!特别推荐一下!!! 首先下载deepin系统ISO镜像,https://...
Python中字典的value是列表的运用 BLOG

Python中字典的value是列表的运用

今天群里一个朋友问了一个python问题,将列表a里的内容 转换成列表b那种格式,示例如下 a= 转换成: b= 简单来说 就是统计相同schema跟table的内容合并到一个list里面 一开始一直...
Python爬取DWR框架的网站 Python

Python爬取DWR框架的网站

最近有个爬取竟台数据的需求,在写python代码的时候,遇到了对方是DWR框架网站。用Chrome开发者工具一看,Post提交参数一堆字典,头都大了。 网站Hearders and Request b...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: