1出现decode错误,意为字符集错误
错误提示是这样的
File "/usr/local/lib/python3.7/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'
解决办法:
打开 /usr/local/lib/python3.7/site-packages/django/db/backends/mysql/operations.py这个文件
找到这段代码:
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.
query = getattr(cursor, '_executed', None)
if query is not None:
query = query.decode(errors='replace')
return query
将其中的query = query.decode(errors='replace')
改为 query = query.encode(errors='replace')
完美解决