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行,原来的代码是这样的
![Django(12)项目报错AttributeError:](https://s2.51cto.com/images/blog/202105/19/3c13a7fa3eb358bf3d2d7bb55185607e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
改为下图所示即可
![Django(12)项目报错AttributeError:](https://s2.51cto.com/images/blog/202105/19/df9edc7a41666eb1a374f3f972ed31d4.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=/resize,m_fixed,w_1184)
这里为了方便,复制下面代码即可
query = query.encode(errors='replace') if isinstance(query, str) else query.decode(errors='replace')
attributeError: 'NoneType' object has no attribute 'shape' 报错
attributeError: 'NoneType' object has no attribute 'shape' 报错
attributeError: 'NoneType' object has no attribute 'shape' 报错 可能是因为没有设置路径,所以返回的类型是None。 改正的方法是,读取图片时把路径也写上
AttributeError: ‘list‘ object has no attribute ‘reshape‘ ‘list‘ object has no attribute ‘reshape‘
def image2vector(image): """ Argument: image -- a numpy array of shape (length, height, depth) Returns: v -- a vector of shape (length*height*depth, 1) """ 将三维变为一维输出 v = np.array(image).reshape(np.array(image).sh.