试用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. Bash 中常见的字符串操作

    获取字符串长度 ${#string} MyString=abcABC123ABCabc 注意这会自动去掉字符串结尾处的空格,如果在字符串中包含空格(开头.中间或结尾),就需要使用引号把字符串包裹起来: ...

  2. 705 B. Spider Man

    传送门 [http://codeforces.com/contest/705/problem/B] 题意 这题意看原文的真tm难懂Woc,但结合样例就知道大概意思了 两个轮流分环,可以这么理解两个人轮 ...

  3. 基于SSH框架的考勤管理系统的设计与实现

    基于SSH框架的考勤管理系统的设计与实现

  4. Spring框架最简单的定时任务调用

    package org.jeecgframework.core.timer; import org.springframework.scheduling.annotation.Scheduled; i ...

  5. 原生js作用域(红宝书)

    function fn(){ ; alert(a); // 2; } alert(a);//未被定义: alert(b);//全局变量:b=2: ; function fn1(){ ; functio ...

  6. 关于js中this指向的理解总结!

    关于js中this指向的理解! this是什么?定义:this是包含它的函数作为方法被调用时所属的对象. 首先,this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁 ...

  7. loadrunner报错

    Action.c(1516): Error -27727: Step download timeout (120 seconds) has expired when downloading resou ...

  8. 时空CLR解密登陆密码源码

    public static SqlString GetPwd(string code ) { string txt = code; if(string.IsNullOrEmpty(txt)) { re ...

  9. Linux文件权限属性后面有个点

    坑啊,新上的机器,监控怎么都不好使,各种报错说:没有权限 什么情况? 仔细查看,发现文件权限属性后面怎么多了个点,类似如下: 这是什么? 原来: 开启了SELinux功能的Linux系统就会有这个点. ...

  10. CF1045G

    CF1045G 看了下题解,动态开点线段树,好像挺难的 #include <map> #include <cstdio> #include <algorithm> ...