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')
相关文章推荐
- 用python爬github上星级排名前列的项目报错AttributeError: 'NoneType' object has no attribute 'decode'
- AttributeError: 'NoneType' object has no attribute 'bytes' python3.4 win64
- Django: AttributeError: 'str' object has no attribute 'resolve'
- 解决Win7(x64)Anaconda3报错:AttributeError: '_NamespacePath' object has no attribute 'sort'
- 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- PIL中分离通道发生“AttributeError: 'NoneType' object has no attribute 'bands'”
- 使用pyinstaller打包为可执行程序后, iptables模块执行时提示 AttributeError: 'NoneType' object has no attribute 'throw_exception'
- Scrapy报错Error: 'module' object has no attribute 'OP_SINGLE_ECDH_USE'
- 创建django项目出现AttrbuteError module 'pip' has no attribute 'main'解决方法
- django view.py error 'function' object has no attribute 'objects' 解决办法
- Python之报错AttributeError:'CocaCola' object has no attribute 'local_logo'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- python问题:AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
- httplib:AttributeError: 'module' object has no attribute 'HTTPConnection'
- 用ride运行脚本报错AttributeError:‘module’ object has no attribute ‘PoolManager’
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute ’urllibopen'(Python 2.7.11 )
- pycharm 安装第三方库报错:AttributeError: 'module' object has no attribute 'main'
- Python python __def__ Exception AttributeError: "'NoneType' object has no attribute