django中mysql版本报错问题

Django运行manage.py时候报错:raise ImproperlyConfigured(‘mysqlclient 1.3.13 or newer is required; you have %s.’ % Dat…

报错位置

File "G:\python\lib\site-packages\django\db\backends\mysql\base.py", line 36, in <module

报错问题

    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

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

解决方案(一)

第一步:点击报错位置找到这两行,注释掉。

在这里插入图片描述

第二步:再次执行python manage.py ,makemigrations 报错
报错路径 <br>File "G:\python\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
    query = query.decode(errors='replace')<br><br> # 报错问题
AttributeError: 'str' object has no attribute 'decode'

修改 :将代码里面query.decode改成:query.encode

if query is not None:
    query = query.encode(errors='replace')  # 修改后的
return query

解决方案(二)

  注意 :如果你注释了上面版本的问题后,运行mamage.py还是报同样的错误,那就是你django版本过高。django版本和pymysql版本匹配不上的问题。
在pycharm中修改django版本

在这里插入图片描述

点击 ‘—’ 号,删除当前的djangp包。

在这里插入图片描述

点击‘+’号,在搜索框中输入django,然后钩上 Specify Version后选择相应版本,最后点击安装。

在这里插入图片描述

再次运行manage.py

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44630560/article/details/104477773