解决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 ...
随机推荐
- Centos7系统下修改主机名操作笔记
习惯了在Centos6系统下修改主机名的操作,但是Centos7下修改主机名的操作却大不相同!操作笔记如下: 在CentOS中,有三种定义的主机名:静态的(static),瞬态的(transient) ...
- 理解Vue 2.5的Diff算法
DOM"天生就慢",所以前端各大框架都提供了对DOM操作进行优化的办法,Angular中的是脏值检查,React首先提出了Virtual Dom,Vue2.0也加入了Virtual ...
- 最好使用%f输出浮点数据,acm
今天做题的时候发现使用%lf输出的时候总是wrong,而一旦改成%f就ac了,询问学长后知道,不要用%lf输出,浮点都用%f 然而我还是有疑惑,如果%f容不下输出的数据怎么办呢? 于是我就去百度 原来 ...
- B. Diagonal Walking v.2
链接 [https://i.cnblogs.com/EditPosts.aspx?opt=1] 题意 二维平面从原点出发k步,要到达的点(x,y),每个位置可以往8个方位移动,问到达目的地最多可以走多 ...
- BugPhobia团队篇章:团队管理与Github源代码管理说明
0x00:序言 To the searching tags, you may well fall in love withhttp://xueba.nlsde.buaa.edu.cn/ 再见,无忧时光 ...
- <<浪潮之巅>>阅读笔记二
好的文章总是慢慢吸引着你去阅读,这本书的作者是吴军博士,让我很钦佩的是他还是一个很著名的程序员.其实我感觉理科生在写作方面的能力是很欠缺的,我们经常做到了有观点,但是做不到和别人表达清楚你的观点想法, ...
- ubuntu——caffe配置deeplab
1. 下载deeplab 2. 安装matio sudo apt-get install libmatio-dev 3. 修改Makefile文件 LIBRARIES += glog gflags p ...
- 第三个sprint冲刺第三阶段
公测版:
- python2 与 python3 实现共存
已有配置 Anaconda2+python2.7 方案一:直接安装官网原生python3.6 1.修改根目录下python.exe ->python3.exe pythonw.exe - ...
- Estimating the number of receiving nodes in 802.11 networks via machine learning
来源:IEEE International Conference on Communications 作者:Matteo Maria 年份:2016 摘要: 现如今很多移动设备都配有多个无线接口,比如 ...