django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.1.

created at 07-16-2021 views: 3

environment

  • python=3.8
  • django=3.1

error message

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.1.

reason

It is using pymysql instead of mysqlclient that caused the error.

Solution

method 1

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

Why do I know you are using pymysql?

Because 0.10.1 is only the latest version of pymysql.

Why use pymysql instead of mysqlclient in the project?

Because it is easier to install. pymysql does not depend on system libraries, while mysqlclient depends on a series of system libraries, such as libmysqlclient-dev.

Why is mysqlclient difficult to install, but Django still uses it by default?

Because mysqlclient is faster and has better performance. Therefore, if your project has high performance requirements, it is recommended that you delete the above compatible code, and then install mysqlclient in the project.

method 2

Install mysqlclient instead of pymysql

pip install mysqlclient

Ubuntu 14,Ubuntu 16,Debian 8.6(jessie)

sudo apt-get install python-pip python-dev libmysqlclient-dev

Fedora 24:

sudo dnf install python python-devel mysql-devel redhat-rpm-config gcc

MacOS

brew install mysql-connector-c

If it fails, try

brew install mysql
Please log in to leave a comment.