django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

created at 07-17-2021 views: 2

environment

  • python3.6
  • django=2.2

reason

When django connects to mysql, MySQLdb is used by default, but MySQLdb does not support python3, and an error is reported when pymysql is used instead.

__init__.py (same directory as settings.py)

import pymysql
pymysql.install_as_MySQLdb()

Solution

method 1: lower the django version

method 2:

1. Find the directory where django\db\backends\mysql is installed. For example, my directory is:

D:\software\python3.6\Lib\site-packages\django\db\backends\mysql

2. Open the base.py file and find the following code

version = Database.version_info

Add pass in if and comment the following code

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

for example

version = Database.version_info
if version < (1, 3, 13):
    pass
    """
        raise ImproperlyConfigured(
            'mysqlclient 1.3.13 or newer is required; you have %s.' 
            % Database.__version__
            )
    """

Then save and close the file.

3. Open the operations.py file

Find the following code:

query = query.decode(errors='replace')

Change decode to encode, as shown below

query = query.encode(errors='replace')

then we can run successfully.

Please log in to leave a comment.