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()
method 1: lower the django version
1. Find the directory where
django\db\backends\mysql is installed. For example, my directory is:
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__)
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.