models 中有如下语句,执行python manage.py makemigrations:
def __str__(self):
return self.name
执行python manage.py makemigrations 报错如下:
File "D:\pythonfile\venv\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'
修改如下,D:\pythonfile\venv\lib\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