django2.2 和 PyMySQL版本兼容問題
錯誤信息為
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
錯誤原因:
因為Django連接MySQL時默認使用MySQLdb驅(qū)動,但MySQLdb不支持Python3,因此這里將MySQL驅(qū)動設(shè)置為pymysql。由此產(chǎn)生的版本兼容問題。
pymysql安裝方法:
#安裝pymysql pip install pymysql #__init__.py import pymysql pymysql.install_as_MySQLdb()
解決辦法:
1. django降到2.1.4版本
2. 修復(fù)源碼
2.1 找到Python環(huán)境下 django包,并進入到backends下的mysql文件夾
# 使用此命令可以看到對應(yīng)的文件夾目錄 ➜ daliyfresh pip install pymysql Looking in indexes: https://mirrors.aliyun.com/pypi/simple/ Requirement already satisfied: pymysql in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (0.9.3)
2.2 找到base.py文件,注釋掉 base.py 中如下部分(35/36行)
if version < (1, 3, 3): raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
2.3 此時仍然報錯,找到operations.py文件,將decode改為encode
AttributeError: ‘str' object has no attribute ‘decode'
解決辦法:
#linux vim 查找快捷鍵:?decode if query is not None: query = query.decode(errors='replace') return query #改為 if query is not None: query = query.encode(errors='replace') return query
測試,執(zhí)行數(shù)據(jù)遷移
python manage.py makemigrations python manage.py migrate
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- mysql 8.0.24版本安裝配置方法圖文教程
- MySQL8.0.24版本Release Note的一些改進點
- mysql的MVCC多版本并發(fā)控制的實現(xiàn)
- MySQL8.0.23版本的root密碼重置最優(yōu)解法
- 關(guān)于MyBatis連接MySql8.0版本的配置問題
- 解決seata不能使用mysql8版本的問題方法
- 詳解DBeaver連接MySQL8以上版本以及解決可能遇到的問題
- IDEA使用mybatis-generator及配上mysql8.0.3版本遇到的bug
- MySQL5.x版本亂碼問題解決方案
- CentOS7版本安裝Mysql8.0.20版本數(shù)據(jù)庫的詳細教程
- Mysql5.7及以上版本 ONLY_FULL_GROUP_BY報錯的解決方法
- 解決mysql8.0.19 winx64版本的安裝問題
- Linux下二進制方式安裝mysql5.7版本和系統(tǒng)優(yōu)化的步驟
- mysql 8.0.18各版本安裝及安裝中出現(xiàn)的問題(精華總結(jié))
- 超詳細教你怎么升級Mysql的版本
相關(guān)文章

Python打包模塊wheel的使用方法與將python包發(fā)布到PyPI的方法詳解