原因:

在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错:
TypeError: __init__() missing 1 required positional argument: 'on_delete'
举例说明:
user=models.OneToOneField(User)
owner=models.ForeignKey(UserProfile)
需要改成:
user=models.OneToOneField(User,on_delete=models.CASCADE) --在老版本这个参数(models.CASCADE)是默认值
owner=models.ForeignKey(UserProfile,on_delete=models.CASCADE) --在老版本这个参数(models.CASCADE)是默认值
参数说明:
on_delete有CASCADE、PROTECT、SET_NULL、SET_DEFAULT、SET()五个可选择的值
CASCADE:此值设置,是级联删除。
PROTECT:此值设置,是会报完整性错误。
SET_NULL:此值设置,会把外键设置为null,前提是允许为null。
SET_DEFAULT:此值设置,会把设置为外键的默认值。
SET():此值设置,会调用外面的值,可以是一个函数。
一般情况下使用CASCADE就可以了。

Django报错:__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. Django在根据models生成数据库表时报错: __init__() missing 1 required positional argument: 'on_delete'

    原因: 在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错:TypeError: __init__() missing ...

  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. Django在根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'

    from django.db import models # Create your models here. class Category(models.Model): caption = mode ...

  6. Python3:Django根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'

    Python3:Django根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete' 一.分析 在 ...

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

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

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

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

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

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

随机推荐

  1. python遇到的错误

    今天学习文件遇到这个错误. 这是在 text_files\vvvv.txt  之间加一个\ 就可以了,变成  text_files\\vvvv.txt,运行成功

  2. layout_weight 全解析

    [layout_weight 全解析] 参考:http://www.cnblogs.com/net168/p/4227144.html

  3. Application类

    using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; usin ...

  4. day22 面向对象基础

    1.什么是面向过程 在介绍面向对象之前,要先明确面向过程 在这之前我们所写的任何代码都是面向过程的 什么是面向过程? 是一种编程思想 面对 朝向 在编写代码时,要时刻想着过程这两个字 过程指的是什么? ...

  5. PHPActiveRecord 学习二

    ORM关联查询 a.一对多 针对外键来说 谁属于谁 谁有谁 user表 CREATE TABLE `user` ( `uid` int(11) NOT NULL AUTO_INCREMENT, `na ...

  6. Navicat连接mysql(高级选项配置)

    .对于服务器上的mysql中存在多个数据库,我们如果全部连接显示,但是平时使用的只有一个库,那么查询的速度会很慢的.所以,今天和大师兄学习了一招.只连接一个自己使用的数据库.配合高级设置,提升很多. ...

  7. 22. Generate Parentheses (backTracking)

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  8. 【转】关于easyui的窗口和tab页面不执行js说明

    原地址:http://www.jeasyuicn.com/post-49.html 一直以来群里里面很多人反应,在用tab加载界面的时候,界面里面的js不会执行.今天GodSon在此说明一下原因. 不 ...

  9. Android Studio生成签名安装包(Generate Signed APK)

    一 打开构建对话框. 二 创建新的密钥库(key store) 可以选择已创建的密钥库,也可以选择创建新的密钥库. 创建完成后,自动导入. 三 选择签名类型. 如果不选,会提示错误. 这里将新旧两种签 ...

  10. 微信小程序接入百度统计

    一. 百度统计添加应用,获取appkey和微信小程序统计sdk: 1. 百度统计首页,点击“我的全部应用”右侧的添加按钮: 2. “应用类型”选择小程序统计,选择微信小程序,填写应用名称信息,选择内容 ...