关于连接MySQL报mysqlclient 1.3.13 or newer is required; you have 0.9.3的问题

问题一:

初学django,在使用django连接MySQL时,在运行python manage.py migrate时,报错如下:

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

后经了解,应该是django的版本限制问题,于是进入C:\Python37\Lib\site-packages\django\db\backends\mysql\base.py中,注释掉如下代码:

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

但是这行代码是针对版本在1.3.13以下的版本的,但是我的是django3.0版本,所以感觉这个应该没用,但是先不管,再次运行python manage.py migrate,这个问题没有出现,但是出现了第二个出错误

问题二:

紧接上一步之后,报错如下:

RuntimeError: cryptography is required for sha256_password or caching_sha2_password

经过网上一堆解决方案之后,有如下方法:
方法一:
查询你的mysql数据库中user表plugin列的值,plugin项下,是否是MySQL_native_password,如果不是,则进行以下操作:
1、ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘password’ PASSWORD EXPIRE NEVER; #修改加密规则
2、ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘123qwe’; #更新一下用户的密码
3、FLUSH PRIVILEGES; #刷新权限
4、再重置下密码:alter user ‘root’@‘localhost’ identified by ‘123qwe’; ps:两个密码我都用的同一个,方便起见
5、重启MySQL服务,我直接先关掉再启动,net 命令
ps:但是这种方法对我貌似没有用。
方法二:
安装cryptography,于是:

pip install cryptography -i https://pypi.tuna.tsinghua.edu.cn/simple module_name

安装成功之后,再次运行python manage.py migrate,数据迁移运行成功。

发布了3 篇原创文章 · 获赞 0 · 访问量 32

猜你喜欢

转载自blog.csdn.net/G36320/article/details/105247404