Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]

Background

python 3.7.6
django 2.2

Phenomenon

Execute Python manage Error in py makemigrations:

  File "E:\software\Python3-64bit\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
    query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'

reason:

The reason is unknown. This problem will occur in some versions.

Solution:

Modify line 146 of {PYHTON_HOME}\lib\site-packages\django\db\backends\mysql\operations.py to change
query = query.decode(errors=’replace’) to query = query.encode(errors=’replace’)

Read More: