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即可。