Django(12)项目报错AttributeError: 'bytes' object has no attribute 'encode'
报错情况
Django使用makemigrations
做数据迁移的时候报如下错误
File "/Users/jkc/.virtualenvs/django_env/lib/python3.7/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
query = query.encode(errors='replace')
AttributeError: 'bytes' object has no attribute 'encode'
解决办法
进入到operations.py
文件中,找到第146行,原来的代码是这样的
改为下图所示即可
这里为了方便,复制下面代码即可
query = query.encode(errors='replace') if isinstance(query, str) else query.decode(errors='replace')