Django链接MySQL数据库,报错"Did you install mysqlclient?"
环境说明:
win10 专业版
python 3.8.4
Django 2.3.1
在一切都配置好之后我操作数据库时,弹出错误
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module
Did you install mysqlclient?
我打开cmd输入pip list确定了我已经安装了mysqlclient 1.4.6版本,然后在网上搜索找到了解决办法:
- 在_init_.py文件中写入
pymysql.install_as_MySQLdb()
- 此时再操作数据库,发现又弹出错误:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2
解决办法:在_init_.py文件中加入下面这条语句
pymysql.version_info=(1,3,13,"final",0)
如图
- 保存后重新运行项目,再执行数据库操作命令
- python manage.py makemigrations
- python manage.py migrate