解决AttributeError: 'str' object has no attribute 'decode'

执行

python3 manage.py makemigrations
报错如下

解决AttributeError: 'str' object has no attribute 'decode'

解决方法如***意替换自己的django的位置)

1. 运行 python ,输入import django

django 或者 django.__file__,找到django安装目录

解决AttributeError: 'str' object has no attribute 'decode'

cd  /usr/local/python3/Python-3.6.5/lib/python3.6/site-packages/django/db/backends/mysql
2

vim operations.py
 

3

找到错误代码(line146):query = query.encode(errors='replace')

解决方法:把decode改为encode即可。

 

4保存并退出。