Django - installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3

Django 2.xx操作mysql数据库时出现如下错误:

mysqlclient 1.3.13 or newer is required; you have 0.9.3

原因是最新的django代码中,有部分地方有改动,这里需要进行一些小修改

首先修改python3.7/site-packages/django/db/backends/mysql路径下的base.py,
找到version = Database.version_info, 把方法中的内容注释掉

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

打开operations.py文件
搜索

query = query.decode(errors='replace')

修改为

query = query.encode(errors='replace')

改完这两处地方应该就ok了

参考:Stack Overflow出处

你可能感兴趣的:(Django - installing mysqlclient error: mysqlclient 1.3.13 or newer is required; you have 0.9.3)