您的位置:首页 > 移动开发 > Objective-C

Django(12)项目报错AttributeError: 'bytes' object has no attribute 'encode'

2021-05-16 09:51 1426 查看

报错情况

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')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐