Django2.X package compatible with PyMySQL


django2.2 version of the module is compatible with pymysql error, error code:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer IS required; you have have 0.9.3

requires mysqlclient need a new version 1.3.13 and later versions

 

Which
mysqlclient is a package python and mysql database link, written in C language.
Pymysql is written in pure python and mysql data link packet. May rival the speed, but wins in the simple installation and easy to use.

Two packets of similar functions, using methods similar

here because the cause of the error django framework (2.2) using the default link package is the mysqlclient , rather than pymysql and use the MySQL returns str force_str in 2.2..
        
        Django2.2 Source:

    def last_executed_query(self, cursor, sql, params):
        # With MySQLdb, cursor objects have an (undocumented) "_executed"
        # attribute where the exact query sent to the database is saved.
        # See MySQLdb/cursors.py in the source distribution.
        # MySQLdb returns string, PyMySQL bytes.
        return force_str(getattr(cursor, ‘_executed‘, None), errors=‘replace‘)


Solution three ways:

1. mysqlclient Alternatively pymysql, python connected with MySQL.

2. Change the django source, commented version mysqlclient judgment,
such as error codes, AttributeError: 'str' object has no attribute 'decode '
at the position corresponding to the error:
the .decode to .encode
or

Importing

from django.utils.encoding import force_str

Use django comes force_str to transform

3. Of course, there is a fallback method to solve this problem, roll back to before the Django framework 2.2 (2.1.4 or earlier)

Guess you like

Origin www.cnblogs.com/jrri/p/11610056.html