解决mysqlclient 1.4.0 or newer is required; you have 0.10.1问题

执行python manage.py makemigrations生成数据库迁移文件时,报错:

    raise ImproperlyConfigured('mysqlclient 1.4.0 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.1.

解决方案:


方案一:在项目的__init__.py中加如下内容:

import pymysql
pymysql.version_info = (1, 4, 13, "final", 0)
pymysql.install_as_MySQLdb()

方案二:
查看pymysql版本

$pip freeze
appdirs==1.4.4
asgiref==3.3.1
cffi==1.14.4
cryptography==3.3.1
distlib==0.3.1
Django==3.1.7
filelock==3.0.12
Pillow==8.1.1
pycparser==2.20
PyMySQL==0.10.1
pytz==2020.4
six==1.15.0
sqlparse==0.4.1
virtualenv==20.4.2

升级pymsql

python3 -m pip install pymysql --upgrade

以上。

你可能感兴趣的:(Python,mysql,python)