Django报错“django.core.exceptions.ImproperlyConfigured: 'django.db.backends.mysql' isn't an *ailable database backend”怎么解决?

django报错“django.core.exceptions.improperlyconfigured: 'django.db.backends.mysql' isn't an available database backend”怎么解决?

解决“django.core.exceptions.improperlyconfigured”错误

在你的代码中,遇到了 "django.core.exceptions.improperlyconfigured: 'django.db.backends.mysql' isn't an *ailable database backend" 错误。这表明 django 无法导入 mysql 后端。

原因

问题在于你的代码实际运行在 python 3.8 而非 3.7 上。python 3.8 中不再内置 mysql 后端。

码上飞 码上飞

码上飞(CodeFlying) 是一款AI自动化开发平台,通过自然语言描述即可自动生成完整应用程序。

码上飞 449 查看详情 码上飞

解决方案

要解决此问题,需要使用第三方包来安装 mysql 后端。具体步骤如下:

  1. 使用 pip 安装 mysqlclient:
pip install mysqlclient
  1. 修改 settings.py 中的 databases 设置:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        ...
    }
}
  1. 确保使用正确的数据库凭据。

重新运行服务器,错误应得到解决。

以上就是Django报错“django.core.exceptions.ImproperlyConfigured: 'django.db.backends.mysql' isn't an *ailable database backend”怎么解决?的详细内容,更多请关注其它相关文章!

本文转自网络,如有侵权请联系客服删除。