Tag Archives: pymysql

Django: How to Solve Using Pymysql Error

Environment:
Ubuntu18.04
mysql:8.0
python: 3.6.8
django: 2.2.6
pymysql: 0.9.3

Install pymysql

pip install pymysql

introduce pymysql into Django

under the package with the same name as the project directory__init__. Write the following code to the PY file:

import pymysql

pymysql.install_as_MySQLdb()

configure MySQL in Django, and then start Django service. The errors are as follows:

File "/home/www/.local/share/virtualenvs/EduScore-UXZMOCwv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

Solution:
Use vim to open /home/www/.local/share/virtualenvs/EduScore-UXZMOCwv/lib/python3.6/site-packages/django/db/backends/mysql/base.py file, and Comment out the following code

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

start Django server and find or report an error. The error information is:

AttributeError: 'str' object has no attribute 'decode'

Solution:

find the corresponding file and change the decode of the error line to encode