解决TypeError: __init__() missing 1 required positional argument: 'on_delete'
试用Djiango的时候发现执行mange.py makemigrations 和 migrate是会报错,少位置参数on_delete,查了一下是因为指定外键的方式不对,改一下就OK了。
代码如下:
from django.db import models
# Create your models here.
class BookInfo(models.Model):
"""model of book infomation"""
# 书的标题 字符串类型 最大长度20
btitle = models.CharField(max_length=20)
# 出版日期 日期类型
bpub_date = models.DateTimeField()
class HeroInfo(models.Model):
"""model of hero information"""
# 英雄的名字 字符串类型 最大长度30
hname = models.CharField(max_length=30)
# 性别 布尔类型
hgender = models.BooleanField()
# 内容 字符串类型 最大长度1000
hcontent = models.CharField(max_length=1000)
# 英雄出现的书 一对多设计 多方持有一方的外键
hbook = models.ForeignKey(BookInfo)
解决方法:
# 英雄出现的书 一对多设计 多方持有一方的外键
# hbook = models.ForeignKey(BookInfo)
hbook = models.ForeignKey('BookInfo', on_delete=models.CASCADE)
解决TypeError: __init__() missing 1 required positional argument: 'on_delete'的更多相关文章
- Django问题 TypeError: __init__() missing 1 required positional argument: 'on_delete'
问题:在执行python manage.py makemigrations learning_logs时,系统会报错,提示:TypeError: __init__() missing 1 requir ...
- 执行python manage.py makemigrations时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'
在执行python manage.py makemigrations时报错: TypeError: __init__() missing 1 required positional argument: ...
- Django :执行 python manage.py makemigrations 时报错 TypeError: __init__() missing 1 required positional argument: 'on_delete'
原因 执行命令 python manage.py makemigrations 报错 TypeError: __init__() missing 1 required positional argum ...
- Django关联数据库时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'
sgrade = models.ForeignKey("Grades",) 执行python manage.py makemigrations后出现TypeError: __ini ...
- python进行数据库迁移的时候显示(TypeError: __init__() missing 1 required positional argument: 'on_delete')
进行数据库迁移的时候,显示 TypeError: __init__() missing 1 required positional argument: 'on_delete' 图示: 出现原因: 在 ...
- TypeError: __init__() missing 1 required positional argument: 'on_delete'
报错的原因呢,就是在设计model时我弄了个外键,然后就报错了... 不难看出,它是想让我们在表与表关联时添加一个on_delete参数 解决办法: 如其所愿,加上on_delete=models.C ...
- 【python3】 django2.0 在生成数据库表时报错: TypeError: __init__() missing 1 required positional argument: 'on_delete'
python: 3.6.4 django: 2.0 models.py 代码如下 # coding: utf-8 from django.db import models from django.co ...
- Django 生成数据库表时的报错TypeError: __init__() missing 1 required positional argument: 'on_delete'
原因及解决办法: https://www.cnblogs.com/phyger/p/8035253.html
- Django2.1在根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'
解决办法: a=models.ForeignKey('BookInfo',on_delete=models.CASCADE,) 即在外键值的后面加上 on_delete=models.CASCADE ...
随机推荐
- 在Ubuntu18.04下将应用程序添加到启动器
# 在启动器里面给应用程序添加一个快捷方式 在linux(ubuntu)平台下,很多小伙伴发现,自己去官网下载解压的软件不能自动添加到启动器,每次启动的时候需要再次进入软件目录输入命令,非常不方便.本 ...
- zabbix监控主机cpu达到80%后报警
在zabbix监控中,默认cpu监控模板中的触发器,当负载在一定时间内(比如最近5分钟)超过5以上为报警阀值.但是在实际场景中,由于服务器配置不一样,这个默认的cpu触发器用起来意义就不大了,这时候就 ...
- linux-shell-命令总结
第一种方法执行: 第二种方法执行: 第三种方法执行: 第四种方法:执行 第三种和第四种方法都是在新的进程里执行程序 函数方法 方法就是一个命令,命令写在字符串的第一个位置 type:可以接外部命令 ...
- 初学习Qt的一些感悟
最近用Qt写了个人项目,有如下心得(可能有不准确): Qt尽管没有扩展C++语法,但是有额外编译链,每个Q_OBJECT类编译的时候会用moc工具生成另一个meta C++类,之后就是标准C++编译流 ...
- beta阶段测试基本概况报告
文件地址 测试基本信息 Bitmap 测试 ...
- 《Linux内核设计与实现》读书笔记三
Chapter 18 调 试 18.1 准备开始 1.准备工作: 一个bug 一个藏匿bug的内核版本 相关内核代码的知识和运气 2.执行foo就会让程序立即产生核心信息转储(dump core). ...
- The Last Reader Response——13-17
Hi, everybody, nice to meet you, this is probably my best and meet you at a time, in the past a seme ...
- [转载]Memory Limits for Windows and Windows Server Releases
Memory Limits for Windows and Windows Server Releases This topic describes the memory limits for sup ...
- shell获取帮助
一.內建命令与外部命令 1.內建命令 内建命令是 shell 程序的一部分,是一些比较简单的 Linux 系统命令,这些命令是写在bash源码的builtins里面的,由 shell 程序识别并在 s ...
- Laravel自定义 封装便捷返回Json数据格式引用
一般返回数据格式 return response()->json(['status' => 'success','code' => 200,'message' => '关注成功 ...