Tracking source code:
Problem file:Python36\lib\site-packages\django\db\backends\mysql\base.py
def get_new_connection(self, conn_params): conn = Database. connect(** conn_params) conn.encoders[SafeText] = conn.encoders[six.text_type] conn.encoders[SafeBytes] = conn.encoders[bytes] return conn
solution
- Downgrade MySQLclient. Uninstall first, then install the specified version.
pip3 uninstall mysqlclient
,pip3 install mysqlclient==1.3
. - My initial solution was to change the django code ( Python36\lib\site-packages\django\db\backends\mysql\base.py ), add an “if” as below:
def get_new_connection(self, conn_params): conn = Database. connect(** conn_params) conn.encoders[SafeText] = conn.encoders[six.text_type] #First determine whether the bytes exist in the encoder, and if so, perform the operation if bytes in conn.encoders: conn.encoders[SafeBytes] = conn.encoders[bytes] return conn