获取TypeError:__init __()缺少1个需要的位置参数:'on_delete'当试图添加父表后面的子表
解决办法:https://stackoverflow.com/questions/44026548/getting-typeerror-init-missing-1-required-positional-argument-on-delete
class Article(models.Model):
titre=models.CharField(max_length=100)
auteur=models.CharField(max_length=42)
contenu=models.TextField(null=True)
date=models.DateTimeField(
auto_now_add=True,
auto_now=False,
verbose_name="Date de parution"
) def __str__(self):
return self.titre
我添加了父表后,现在我models.py看起来像这样: from django.db import models # Create your models here.
class Categorie(models.Model):
nom = models.CharField(max_length=30) def __str__(self):
return self.nom class Article(models.Model):
titre=models.CharField(max_length=100)
auteur=models.CharField(max_length=42)
contenu=models.TextField(null=True)
date=models.DateTimeField(
auto_now_add=True,
auto_now=False,
verbose_name="Date de parution"
)
categorie = models.ForeignKey('Categorie') def __str__(self):
return self.titre
所以当我运行时python manage.py makemigrations <my_app_name>,我得到这个错误: Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\core\management\__init__.py", line 354, in execute_from_command_line
utility.execute()
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\core\management\__init__.py", line 330, in execute
django.setup()
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\lislis\Django\mon_site\blog\models.py", line 6, in <module>
class Article(models.Model):
File "C:\Users\lislis\Django\mon_site\blog\models.py", line 16, in Article
categorie = models.ForeignKey('Categorie')
TypeError: __init__() missing 1 required positional argument: 'on_delete'
class Article(models.Model):
titre=models.CharField(max_length=100)
auteur=models.CharField(max_length=42)
contenu=models.TextField(null=True)
date=models.DateTimeField(
auto_now_add=True,
auto_now=False,
verbose_name="Date de parution"
)
def __str__(self):
return self.titre
我添加了父表后,现在我models.py看起来像这样:
from django.db import models
# Create your models here.
class Categorie(models.Model):
nom = models.CharField(max_length=30)
def __str__(self):
return self.nom
class Article(models.Model):
titre=models.CharField(max_length=100)
auteur=models.CharField(max_length=42)
contenu=models.TextField(null=True)
date=models.DateTimeField(
auto_now_add=True,
auto_now=False,
verbose_name="Date de parution"
)
categorie = models.ForeignKey('Categorie')
def __str__(self):
return self.titre
所以当我运行时python manage.py makemigrations <my_app_name>,我得到这个错误:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\core\management\__init__.py", line 354, in execute_from_command_line
utility.execute()
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\core\management\__init__.py", line 330, in execute
django.setup()
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django-2.0-py3.5.egg\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\lislis\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\lislis\Django\mon_site\blog\models.py", line 6, in <module>
class Article(models.Model):
File "C:\Users\lislis\Django\mon_site\blog\models.py", line 16, in Article
categorie = models.ForeignKey('Categorie')
TypeError: __init__() missing 1 required positional argument: 'on_delete'
获取TypeError:__init __()缺少1个需要的位置参数:'on_delete'当试图添加父表后面的子表的更多相关文章
- sql 2000以及2005以上获取数据库中所有的表(不包括系统表)
---------------------------------------------------------------------------- --sql 2005以上数据库 --- 获取数 ...
- JS获取父、兄、子节点
一.jQuery的父节点查找方法 $(selector).parent(selector):获取父节点 $(selector).parentNode:以node[]的形式存放父节点,如果没有父节点,则 ...
- layui 父页面获取弹窗传递的值 和 父页面传值给子弹窗的方法
1.父页面获取子页面(弹窗)的值: 现在父页面页面加载方法中定义方法,专门用来获取从子页面的值 $(document).ready(function() { //拿到子窗口中传回的数据 functio ...
- layui父表单获取子表单的值完成修改操作
最近在做项目时,学着用layui开发后台管理系统. 但在做编辑表单时遇到了一个坑. 点击编辑时会出现一个弹窗. 我们需要从父表单传值给子表单.content是传值给子表单 layer.open({ t ...
- 用 getElementsByTagName() 来获取,父元素指定的子元素
1. html 结构 <ul> <li>知否知否,应是等你好久11</li> <li>知否知否,应是等你好久11</li> <li&g ...
- [译]为什么在__new __()后总是调用__init __()?
原文来源: https://stackoverflow.com/questions/674304/why-is-init-always-called-after-new 需要控制新实例的创建时,请使用 ...
- java图片上传,通过MultipartFile方式,如果后台获取null检查是否缺少步骤
本方法基于springMvc 1.首先需要在webap下创建images 2.在springmvc.xml上引入 <bean id="multipartResolver" c ...
- springmvc下js控制表单提交(表单提交前检验,提交后获取json返回值)
这个问题我搞了四天,终于搞懂.因为对js很不熟悉.郁闷的是后台代码出错总可以设置断点调试,前端js代码出错只能通过浏览器提供一些运行数据来分析,很不习惯. 首先说下逻辑:这是一个注册功能,我希望,注册 ...
- js 获取当前焦点所在的元素、给元素和input控件添加键盘监听事件、添加页面级的键盘监听事件
页面级的键盘监听事件 document.onkeydown = function (event) { var e = event || window.event || arguments.callee ...
随机推荐
- 互评Final版本
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2478] 基于NABCD评论作品,及改进建议 杨老师粉丝群.作品:<Pin ...
- C:基础知识
基础知识 一.基础转义字符 1.常用的转义字符 \n 回车换行 (10) \” 双引号 \t 横向跳格(9) \0 空字符(0) \v 竖向跳格 (11) \a 响铃(7) \b 退格 (8) \ ...
- Nginx日志和http模块相关变量
$arg_PARAMETER #HTTP 请求中某个参数的值,如/index.php?site=www.ttlsa.com,可以用$arg_site 取得 www.ttlsa.com 这个值. $ar ...
- 点击图片或者鼠标放上hover .图片变大. 1)可以使用css中的transition, transform 2) 预先设置一个 弹出div. 3)弹出层 alert ; 4) 浏览器的宽度document.documentElement.clientWidth || document.body.clientWidth
变大: 方法一: 利用css属性. 鼠标放上 hover放大几倍. .kecheng_02_cell_content img { /*width: 100px; height: 133px;*/ wi ...
- ES脑裂问题
脑裂:一个集群中的不同节点对于集群的状态有了不一样的理解 ES集群的总体状态是red,本来9个节点的集群在结果中只显示4个节点在线: 正常情况下,集群中的所有节点应该对集群中的master的选择是一致 ...
- 使用git下载源码及数据文件
初学git,用来下载github上的数据和源代码,具体步骤如下. 1.百度搜索git并下载:本想从github直接下载安装,无奈国外服务器的下载速度太慢,建议国内的直接搜索下载完整安装版. 2.完成g ...
- hmtl工具
在线编辑器:http://runjs.cn/code 关注微信小程序
- LeetCode—66、88、118、119、121 Array(Easy)
66. Plus One Given a non-negative integer represented as a non-empty array of digits, plus one to th ...
- 小程序 textarea
1.小程序中textarea不能在scroll-view.swiper.picker-view等等里面运用. 2.不在fixed布局的页面中,placeholder也会随着页面滚动,解决方法:顶级父元 ...
- [转]Peer-to-Peer Communication Across Network Address Translators
Peer-to-Peer Communication Across Network Address Translators Bryan Ford Massachusetts Institute of ...