解决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 ...
随机推荐
- Net-SNMP V3协议 安装配置笔记(CentOS 6.3/5.6)
注意:snmp V3,需要需要关闭selinux和防火墙: 关闭selinux方法: #vi /etc/selinux/config 将文件中的SELINUX="" 为 disab ...
- PHP从入门到精通(三)
PHP数组的分类 按照下标的不同,PHP数组分为关联数组与索引数组: 索引数组:下标从0开始,依次增长:关联数组: 下标为字符串格式,每个下标字符串与数组的值一一关联对应.(有点像对象的键值对) 关于 ...
- python基础学习笔记(十三)
re模块包含对 正则表达式.本章会对re模块主要特征和正则表达式进行介绍. 什么是正则表达式 正则表达式是可以匹配文本片段的模式.最简单的正则表达式就是普通字符串,可以匹配其自身.换包话说,正则表达式 ...
- 个人博客作业_week7
心得 在为期将近一个月的团队编程中,给我感受最深的是敏捷开发和团队中队员之间的互补. 在最初的软件开发中,由于以前没有这方面的经验,所以并没有很大的进展.在慢慢过度中,我们找到了自己的节奏感,大家各自 ...
- 2丶利用NABCD模型进行竞争性需求分析
确定项目:公交查询系统 分析小组:在路上 选择比努力更重要.一个项目成功自然离不开组员们的努力.但是,光努力是不够的.还需要用户有需求,能快速实现. 这些东西,看似很虚,却能让我们少走不少弯路.做项目 ...
- HDOJ2099_整数的尾数
一道我以为不会这么简单,然后暴力盲打竟然给过了的题. HDOJ2099_整数的尾数 #include<stdio.h> #include<stdlib.h> #include& ...
- Doors Breaking and Repairing CodeForces - 1102C (思维)
You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consi ...
- 2017[BUAA软工]第0次个人作业
第一部分:结缘计算机 1.你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢? ●其实填写志愿之前并不知道要学什么专业,当初选择计算机是因为计算机就业前景好.方向多.计算机应用的领域无处不在, ...
- MySQL基础~~表结构操作
登录数据库服务器 mysql -h127.0.0.1 -uroot -p123456 创建数据库 create database test; 显示所有数据库 show databases; 指定要操作 ...
- K Nearest Neighbor 算法
文章出处:http://coolshell.cn/articles/8052.html K Nearest Neighbor算法又叫KNN算法,这个算法是机器学习里面一个比较经典的算法, 总体来说KN ...