“django.core.exceptions.improperlyconfigured”錯(cuò)誤:解決方案
在嘗試運(yùn)行 django 項(xiàng)目時(shí),你可能會(huì)遇到以下錯(cuò)誤:
django.core.exceptions.improperlyconfigured: 'django.db.backends.mysql' isn't an available database backend or couldn't be imported.
原因
此錯(cuò)誤通常是因?yàn)橐韵略蚨l(fā)生的:
- django 無法導(dǎo)入 mysql 數(shù)據(jù)庫(kù)后端。
- 你在 django 的 databases 設(shè)置中配置了 mysql 但未安裝正確的后端。
解決方案
檢查 python 版本
確保你確實(shí)使用的是 python 3.7.4,而不是 3.8.6。
確保安裝了適當(dāng)?shù)臄?shù)據(jù)庫(kù)后端
對(duì)于 django 3.2.19 和 mysql,安裝 mysqlclient 包:
pip install mysqlclient
驗(yàn)證配置
檢查你的 django settings.py 文件中的 databases 設(shè)置是否正確。確保擁有以下內(nèi)容:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': '你的數(shù)據(jù)庫(kù)名稱', 'USER': '你的數(shù)據(jù)庫(kù)用戶', 'PASSWORD': '你的數(shù)據(jù)庫(kù)密碼', 'HOST': '你的數(shù)據(jù)庫(kù)主機(jī)', 'PORT': '你的數(shù)據(jù)庫(kù)端口', } }
確保使用的 engine 值為 django.db.backends.mysql。
其他提示
- 嘗試重新啟動(dòng) django 項(xiàng)目或服務(wù)器。
- 確保你的 mysql 數(shù)據(jù)庫(kù)正在運(yùn)行。
- 檢查你的 manage.py 文件是否與 django 版本兼容。
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END