最近在《phthon 从入门到实战》在第19章第三部分,按照要求在models.py(learning_logs app 里面的),添加了一行:owner=models.ForeignKey(User,on_delete=models.CASCADE),即添加了用户的一个外键,在执行了makemigrations 后,sunsever 时出现了一个错误,如下:

无对应列owner_id,出现这个错误的原因是makemigrations 是告诉数据库添加了新列,但没有将改动应用于数据库,migrate则是将改动应用于数据库,关于makemigrations 和migrate 的区别,以下是摘自Moderator Chris Freeman的回答

"It is necessary to run both the commands to complete the migration of the database tables to be in sync with your models.

makemigrations simply analyzes your current models for any changes that would be out of sync with your database and creates a migrations file that can be used to bring the in sync. If left at this point, your models would still be out of sync with your database possibly breaking your code that queries the database.

migrate is the command to "Make It So!" and apply the changes noted during the makemigrations phase.

Applying [app] to either of these commands simply adds focus to that "app" and doesn't inspect all of your apps."

所以是忘了执行“migrate”,执行后错误消失。makemigrations、migrate 都是必要的。

sqlite3.OperationalError: no such column: **相关推荐

  1. django.db.utils.OperationalError: no such column: catalogue_product.is_public

    报错来自django-oscar从低版本向高版本迁移的时候发生的. 完整报错如下: Traceback (most recent call last):   File "/home/appl ...

  2. python操作sqlite报错:sqlite3.OperationalError: unrecognized token: “630008.OF“

    python操作sqlite报错:sqlite3.OperationalError: unrecognized token: "630008.OF" 分析:Ana:column的名 ...

  3. 解决 “OperationalError: (sqlite3.OperationalError) no such table: ...“问题

    解决 "OperationalError: (sqlite3.OperationalError) no such table: ..."问题 参考文章: (1)解决 "O ...

  4. sqlite3.OperationalError: database is locked

    情景描述 windows上代码文件,设置为共享目录,mount到linux使用.运行python manage.py migrate,出现错误 报错 [root@localhost sqlalchem ...

  5. python创建sqlite3 unicode error_python/sqlite3:发生异常:sqlite3.operationalerror

    我正在尝试创建一个函数来处理API错误消息,但是我在python中得到了这个错误消息: Exception has occurred: sqlite3.OperationalError near &q ...

  6. pymysql.err.OperationalError: (1054, “Unknown column ‘xxx‘ in ‘where clause‘“)问题解决方法

    任务 向mysql数据库用户表中加入用户头像图片,一般16M以下的图片类型选择MEDIUMBLOB即可. 遇到问题 用pymysql向mysql插入图片数据时报错:pymysql.err.Operat ...

  7. sqlite报错:sqlite3.OperationalError: near “updata“: syntax error

    sqlite报错:sqlite3.OperationalError: near "updata": syntax error 在进行sqlite操作时,很容易因为看错或者手误造成报 ...

  8. sqlite3.OperationalError: near “(“: syntax error

    错误描述:sqlite3.OperationalError: near "(": syntax error 错误原因: Traceback (most recent call la ...

  9. 解决 pymysql.err.OperationalError: (1054, “Unknown column ‘xxx‘ in ‘where clause‘“)

    解决 python 对mysql执行操作时报错: pymysql.err.OperationalError: (1054, "Unknown column 'xxx' in 'where c ...

最新文章

  1. HTTP的四种请求方法
  2. oracle 10g 安装介质,如何从Oracle 10g的安装介质中提取BBED必须的sbbdpt.o和ssbbded.o库文件...
  3. linux下exec系列(一)
  4. 采用存储复制方式同步数据,实现数据库安全升级
  5. android 语音阅读软件,语音阅读器APP
  6. 【转】windows多线程CreateThread与_beginthreadex本质区别
  7. 外媒:伊朗政府封锁加密通讯应用Signal
  8. springboot线程池配置
  9. 如何在Ubuntu Linux上安装JDK
  10. 7x android 8,内测开启 华为荣耀畅玩7X升级Android 8.0
  11. 编程实现二叉树的遍历
  12. html5json转换为数组,Json转数组 在线
  13. 简单粗暴日文键盘布局改为其他语言键盘布局
  14. 心回暖------振作
  15. 各个框架原理总结归纳
  16. java面试项目中遇到难题,大量教程
  17. php统计结果,使用php怎么统计问卷调查结果
  18. Linux ln -s目录,Linux ln 命令的使用
  19. 北理工计算机学院沈建斌,沈建冰_北京理工大学计算机学院
  20. 未来5年光通信系统十大技术趋势发布

热门文章

  1. JDBC粗略学习( 阿巴阿巴阿巴阿巴)
  2. html绘制word柱状图,word如何制作柱状图
  3. linux判断值相等_Shell字符串比较相等、不相等方法小结【转】
  4. 实习日志_实习律师实习日志第十八篇(连载30篇)
  5. Java练习02 打印三角形
  6. 功放音量调节原理_汽车音响知识关于功放和低音喇叭的匹配
  7. win7计算机菜单,教您win7右键菜单设置方法
  8. mysql general bin区别_MySQL_编码utf8_bin和utf8_general_ci的区别
  9. cheaklist 人机交互界面_10个人机交互系统及界面的设计方案
  10. java 增长因子_Java ArrayList的扩容因子为什么是1.5?