试用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'的更多相关文章

  1. Django问题 TypeError: __init__() missing 1 required positional argument: 'on_delete'

    问题:在执行python manage.py makemigrations learning_logs时,系统会报错,提示:TypeError: __init__() missing 1 requir ...

  2. 执行python manage.py makemigrations时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    在执行python manage.py makemigrations时报错: TypeError: __init__() missing 1 required positional argument: ...

  3. 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 ...

  4. Django关联数据库时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    sgrade = models.ForeignKey("Grades",) 执行python manage.py makemigrations后出现TypeError: __ini ...

  5. python进行数据库迁移的时候显示(TypeError: __init__() missing 1 required positional argument: 'on_delete')

    进行数据库迁移的时候,显示  TypeError: __init__() missing 1 required positional argument: 'on_delete' 图示: 出现原因: 在 ...

  6. TypeError: __init__() missing 1 required positional argument: 'on_delete'

    报错的原因呢,就是在设计model时我弄了个外键,然后就报错了... 不难看出,它是想让我们在表与表关联时添加一个on_delete参数 解决办法: 如其所愿,加上on_delete=models.C ...

  7. 【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 ...

  8. Django 生成数据库表时的报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    原因及解决办法: https://www.cnblogs.com/phyger/p/8035253.html

  9. Django2.1在根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'

    解决办法: a=models.ForeignKey('BookInfo',on_delete=models.CASCADE,) 即在外键值的后面加上 on_delete=models.CASCADE ...

随机推荐

  1. 对PS的评价

    Photoshop(简称:PS)是电脑上的图像处理软件:对于广大Photoshop爱好者而言,PS亦用来形容通过该类图形处理软件处理过的图片,即非原始.非未处理的图片:多数人对于这软件的了解仅限于“一 ...

  2. Qt_颜色选择对话框(QColorDialog)

    转自豆子空间 使用QColorDialog也很简单,Qt提供了getColor()函数,类似于QFileDialog的getOpenFileName(),可以直接获得选择的颜色. include &l ...

  3. ubuntu查看本地ip

    1.下载net-tools sudo apt-get install net-tools 2.终端输入命令 ifconfig

  4. Python 零基础 快速入门 趣味教程 (咪博士 海龟绘图 turtle) 5. 参数

    上一个教程中,咪博士带大家学习了函数的使用.例如,line_without_moving 函数,可以让海龟先画出一条线段,然后再回来起点. def line_without_moving(): tur ...

  5. 微信小程序入門學習資料鏈接

    https://blog.csdn.net/github_38847071/article/details/73250258 https://blog.csdn.net/lily2016n/artic ...

  6. Cenos7 添加service,开机启动

    本地有一个 data-service.jar 1. 编写启动脚本  data-service-start [root@iz2ze0fq2isg8vphkpos5sz shell]# more data ...

  7. Spark_RDD之基本RDD操作

    1.基本转化操作    1.1最常用的两个转化操作时map()和filter(). map()接收一个函数,把这个函数用于RDD中的每个元素,将函数作用之后的结果作为结果RDD中元素的值. filte ...

  8. BZOJ3750[POI2015]Pieczęć——链表

    题目描述 一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色. 你有一个a*b的印章,有些格子是凸起(会沾上墨水)的.你需要判断能否用这个印章印出纸上的图案.印的过程中需要满足以下要求: ...

  9. BZOJ3697采药人的路径——点分治

    题目描述 采药人的药田是一个树状结构,每条路径上都种植着同种药材.采药人以自己对药材独到的见解,对每种药材进行了分类.大致分为两类,一种是阴性的,一种是阳性的.采药人每天都要进行采药活动.他选择的路径 ...

  10. POJ2635-The Embarrassed Cryptographer-大整数素因子

    计算一个大整数(10^100)中有没有一个小于L的素因子.这个大整数是两个素数的乘积.其实就是RSA加密. 做法是把大整数表示成千进位,用数组存储,然后一位一位地取模. /*------------- ...