在配置完mysql 的配置信息后执行 python manage.py runserver 时出现如下错误。(py3的环境)

Django 使用mysql 所遇到问题一:Error loading MySQLdb module

解决

在 python2 中,使用 pip install mysql-python 进行安装连接MySQL的库,使用时 import MySQLdb 进行使用

在 python3 中,改变了连接库,改为了 pymysql 库,使用pip install pymysql 进行安装,直接导入import pymysql使用

本来在上面的基础上把 python3 的 pymysql 库安装上去就行了,但是问题依旧

经过查阅得知, Django 依旧是使用 py2 的 MySQLdb 库的,得到进行适当的转换才行

__init__.py 文件中添加以下代码

import pymysql
pymysql.install_as_MySQLdb()

相关文章:

  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2021-05-16
  • 2021-04-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
猜你喜欢
  • 2021-06-17
  • 2021-07-27
  • 2021-07-22
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2021-12-21
相关资源
相似解决方案