1、Django项目中,要在数据库表user里新增一个字段,比如status,在apps的student底下的model写好这个字段的类型,以及是否为空等等之后,执行以下命令:

python manage.py makemigrations student

2、之后提示成功添加一个字段,在migrations目录底下生成了一个0101_user_status.py文件,在执行命令:

python manage.py sqlmigrate student 0101

3、报以下错误:AttributeError: module 'pymysql' has no attribute 'escape'

4、解决办法,在import pymysql的初始化文件__init__.py当中,源代码是这样的:

import pymysql
pymysql.install_as_MySQLdb()

修改代码如下:

import pymysql
pymysql.install_as_MySQLdb()def mysqldb_escape(value, conv_dict):from pymysql.converters import encodersvtype = type(value)# note: you could provide a default:# PY2: encoder = encoders.get(vtype, escape_str)# PY3: encoder = encoders.get(vtype, escape_unicode)encoder = encoders.get(vtype)return encoder(value)import pymysql
setattr(pymysql, 'escape', mysqldb_escape)
del pymysql

之后重新执行上面第二点的命令:python manage.py sqlmigrate student 0101 便成功执行了,参考文章:https://github.com/PyMySQL/PyMySQL/issues/273

5、最后,再执行命令:

 python manage.py migrate

6、这样就在user表中增加了status这个字段,以上内容仅供学习参考,谢谢!

AttributeError: module 'pymysql' has no attribute 'escape' 错误的出现以及解决相关推荐

  1. AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘错误解决

    AttributeError: module 'tensorflow' has no attribute 'Session'错误解决 根据网上教程安装tensorflow环境时,最后都会有个测试代码用 ...

  2. AttributeError: module 'tensorflow' has no attribute 'Session'错误解决

    Ubuntu刚安装好Tensorflow以后运行 import tensorflow as tf tf.Session() 报错AttributeError: module 'tensorflow' ...

  3. python脚本AttributeError: module 'xxxx' has no attribute 'xxxxx'错误解决办法

    最近写脚本发现了这样的一个错误,脚本.环境什么的完全正确,但执行的时候却报错:AttributeError: module 'xxxx' has no attribute 'xxxxx',查阅了一些相 ...

  4. AttributeError: module 'easygui' has no attribute 'msgbox'错误

    初学python 遇到了AttributeError: module 'easygui' has no attribute 'msgbox' 分享一个亲测有效的办法 第一步 cmd–> pip ...

  5. AttributeError: module ‘urllib‘ has no attribute ‘urlopen‘错误

    从网络读取图像数据并转换成图片格式的时候 查了些资料,因为在在Python3.X中应该用urllib.request 修改之后就可以了

  6. PyQt5系列(三)Python3.x AttributeError: module 'string' has no attribute 'maketrans'错误解决

    解决: 1./usr/local/lib/python3.6/site-packages/PyQt5/uic/port_v2/ascii_upper.py修改  _ascii_trans_table ...

  7. AttributeError: module 'requests' has no attribute 'get'错误解析

    报错原因:文件名和模块名冲突 如图所示,看了很久没有发现代码有啥问题,但是就是报错,经排查是因为文件名是requests.py,和import模块导入requests冲突了,系统会认为我们导入的是当前 ...

  8. 关于错误”AttributeError: module 'resource' has no attribute 'getrusage'”

    windows平台下,scrapy1.8.0运行会出现"AttributeError: module 'resource' has no attribute 'getrusage'" ...

  9. tensorflow2.0及以上版本在使用Session模块时报错:AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘ 已解决

    tensorflow2.0版本及之后的版本在使用Session模块时报错:AttributeError: module 'tensorflow' has no attribute 'Session' ...

最新文章

  1. hp远程桌面服务器,hp服务器通过ilo远程安装操作系统
  2. 深度特征提取方法_深度学习|三维重建:StereoDRNet
  3. vue路由切换组件没有加载_Vue面试题: 如何实现路由懒加载?
  4. mysql运维命令_运维常用 MySQL 命令
  5. 清华大学2016年软件学院攻读工程硕士专业学位研究生培养方案
  6. 利用composer搭建PHP框架(三.模板引擎)
  7. 宝塔面板部署网易云api
  8. 随机森林实现回归预测(糖尿病数据集)
  9. 微信小程序开发实战1 微信小程序开发概述
  10. Mac 无法打开淘宝,天猫,京东等
  11. 数据科学和人工智能技术笔记 十八、Keras
  12. element提交图片限制一张_ElementUI 上传文件以及限制
  13. hdu 2167 Pebbles 状态压缩dp
  14. 关于ubuntu 16.04 无法从挂起唤醒及无法关机、卡在关机界面的解决办法
  15. Ardupilot环境搭建
  16. Python3: 简易的 HTTP 服务器 - http.server
  17. C#小工具 ---- 压缩图片并指定图片大小
  18. python操作数据库教程_python通用数据库操作工具 pydbclib|python基础教程|python入门|python教程...
  19. java中怎么实现指数幂,java中幂指数值的运算代码解析
  20. 手机python软件怎么下载词云_从零开始教你用 Python 做词云

热门文章

  1. 万恶之源 - Python基础知识补充
  2. redux-saga基本用法
  3. Dependency Walker使用说明[转]
  4. 初学者web前端知识点--HTML部分
  5. WebSocket实践
  6. C#树状图 初始默认选中节点
  7. 今天项目中遇到一个关于DataGrid的 ItemDataBound自动判断下拉列表默认值绑定问题...
  8. BOM操作及DOM表单案例练习
  9. 解决ie6中fixed不起作用的问题
  10. HEML、CSS、Javascript基础知识总结