解決“django.core.exceptions.improperlyconfigured”錯誤
在你的代碼中,遇到了 “django.core.exceptions.improperlyconfigured: ‘django.db.backends.mysql‘ isn’t an available database backend” 錯誤。這表明 django 無法導入 mysql 后端。
原因
問題在于你的代碼實際運行在 python 3.8 而非 3.7 上。Python 3.8 中不再內置 mysql 后端。
解決方案
要解決此問題,需要使用第三方包來安裝 mysql 后端。具體步驟如下:
pip install mysqlclient
登錄后復制
- 修改 settings.py 中的 databases 設置:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', ... } }
登錄后復制
- 確保使用正確的數據庫憑據。
重新運行服務器,錯誤應得到解決。