django2.2+pymysql0.9.3報錯


最近看django視頻時,由於視頻較老,在配置數據庫時出現以下錯誤:

報錯環境 python=3.6,django=2.2,PyMySQL=0.9.3

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

 PyMySQL 是在 Python3.x 版本中用於連接 MySQL 服務器的一個庫,Python2中則使用mysqldb。PyMySQL 目前版本最高是0.9.3,和django所需版本不符。

解決方案一:

使用低版本django如,django2.1.7。

解決方案二:

不使用 PyMySQL,使用mysqlclient。

解決方案三:

注釋掉django/db/backends/mysql/base.py文件的第35、36行:

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

再次開啟服務器,報錯如下:

AttributeError: ‘str’ object has no attribute ‘decode’

定位報錯位置:

if query is not None:
    query = query.encode(errors='replace')
return query

將'decode'改為'encode'即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM