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')


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM