Django2.2的坑真多
推荐2.1
cursor.execute('SELECT @@SQL_AUTO_IS_NULL')
File "/Applications/anaconda3/envs/env_shan/lib/python3.6/site-packages/django/db/backends/utils.py", line 103, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/Applications/anaconda3/envs/env_shan/lib/python3.6/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'
找到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
将其中两行注释