Python3.6+Django2.2+mysql5.6数据库报错:AttributeError: ‘str’ object has no attribute ‘decode’
File "F:\Project\PythonEnve\***\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'
解决方法:
operations.py *添加一行,**直接返回query数据,结果就可以正常生成了。
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.encode()**
query = query.decode(errors='replace')
return query
本文介绍了一个关于Python3.6环境下使用Django2.2与mysql5.6数据库时遇到的AttributeError错误:'str' object has no attribute 'decode'。通过修改operations.py文件中的last_executed_query方法,直接返回query数据,解决了该问题。
720

被折叠的 条评论
为什么被折叠?



