解决TypeError: __init__() missing 1 required positio
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决TypeError: __init__() missing 1 required positio相关的知识,希望对你有一定的参考价值。
解决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 positio的主要内容,如果未能解决你的问题,请参考以下文章
TypeError: __init__() 接受 1 个位置参数,但给出了 3 个
TypeError:__init__() 得到了一个意外的关键字参数“categorical_features”:onehotencoder
亲测已解决TypeError: __init__() takes 1 positional argument but 2 were given
Python报错:TypeError: __init__() got an unexpected keyword argument 'io_loop' 原因及解决方案
TypeError:__ init __()占用1个位置参数,但给出3个
执行python manage.py makemigrations时报错TypeError: __init__() missing 1 required positional argument: