django 出现 mysqlclient 1.3.13 or newer is required; you have 0.93

代码运行环境说明:
Python:3.7.2
Django:2.2.1
PyMySQL:0.9.3
执行数据库迁移时出现以下提示:

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

网上查资料发现解决方法有三种:

  • I、将你的Django降低到2.14以下即可:这个不用想,老子就要用最新的
  • II、升级的mysql客户端版本至更高:电脑同时运行的还有php等其他语言,懒得折腾
  • III、按照以下步骤修改代码:

     

    image.png

  1. 按图找到你Django目录下的base.py文件
if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

麻溜的找到这两行代码并注释掉。
如果执行以上操作,重新迁移数据库没问题那正好ok,没有的话接着看。
如果出现提示:

File "D:\Program Files\Python37\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
    query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
  1. 那就打开上图中的operations.py文件,上面说的很清楚了,14行中的decode改为encode即可。
    如此,完美!!!!
发布了144 篇原创文章 · 获赞 77 · 访问量 538万+

猜你喜欢

转载自blog.csdn.net/wtl1992/article/details/102983351