Django報(bào)錯(cuò)“django.core.exceptions.ImproperlyConfigured: ‘django.db.backends.mysql’ isn’t an available database backend”怎么解決?

Django報(bào)錯(cuò)“django.core.exceptions.ImproperlyConfigured: ‘django.db.backends.mysql’ isn’t an available database backend”怎么解決?

解決“django.core.exceptions.improperlyconfigured”錯(cuò)誤

在你的代碼中,遇到了 “django.core.exceptions.improperlyconfigured: ‘django.db.backends.mysql‘ isn’t an available database backend” 錯(cuò)誤。這表明 django 無(wú)法導(dǎo)入 mysql 后端。

原因

問(wèn)題在于你的代碼實(shí)際運(yùn)行在 python 3.8 而非 3.7 上。python 3.8 中不再內(nèi)置 mysql 后端。

解決方案

要解決此問(wèn)題,需要使用第三方包來(lái)安裝 mysql 后端。具體步驟如下:

  1. 使用 pip 安裝 mysqlclient:
pip install mysqlclient
  1. 修改 settings.py 中的 databases 設(shè)置:
DATABASES = {     'default': {         'ENGINE': 'django.db.backends.mysql',         ...     } }
  1. 確保使用正確的數(shù)據(jù)庫(kù)憑據(jù)。

重新運(yùn)行服務(wù)器,錯(cuò)誤應(yīng)得到解決。

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊9 分享