Ubuntu django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required

博客主要讲述Django部署到Ubuntu 16.04迁移数据库时,因用pymysql替换mysqlClient且版本不匹配而报错的问题。给出了Windows和Ubuntu系统下的解决方案,Windows需注释抛异常代码,Ubuntu要找到相关位置修改,运行迁移报错后将decode改为encode。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

问题

Django部署到ubuntu16.04,迁移数据库时出现此报错,无法连接至数据库,后来了解到由于用pymysql替换了mysqlClient 而pymysql是0.9.3版本,而django检测的连接数据库模块为mysqlClient的版本,所以才会抛此异常

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

解决方案:

Windows

找到django中的抛异常代码进行注释。
引用该作者的windows解决方案

http://www.mamicode.com/info-detail-2537289.html

在这里插入图片描述

Ubuntu

同样需要先找到python第三方库的安装位置,以及Django的位置,然后修改对应位置,具体操作为:

pip show django
cd /usr/local/lib/python3.5/dist-packages/
cd django/db/backends/mysql/
vim base.py
""" if version < (1, 3, 3):
     raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)"""

然后再运行项目迁移会报另一个错

query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'

此时再执行

vim /usr/local/lib/python3.5/dist-packages/django/db/backends/mysql/operations.py
 

找到错误代码(line146):query = query.encode(errors=‘replace’)

解决方法:把decode改为encode即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值