博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Django在根据models生成数据库表时报
阅读量:6801 次
发布时间:2019-06-26

本文共 2251 字,大约阅读时间需要 7 分钟。

D:\TOOL\PycharmProjects\python3\BS\h2>python manage.py makemigrations

Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:\Program Files\python3.6\lib\site-packages\django\core\management__init__.py", line 371, in execute_from_command_line
utility.execute()
File "D:\Program Files\python3.6\lib\site-packages\django\core\management__init.py", line 347, in execute
django.setup()
File "D:\Program Files\python3.6\lib\site-packages\django\
init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\Program Files\python3.6\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "D:\Program Files\python3.6\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "D:\Program Files\python3.6\lib\importlib\
init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\TOOL\PycharmProjects\python3\BS\h2\booktest\models.py", line 11, in <module>
class HeroInfo(models.Model):
File "D:\TOOL\PycharmProjects\python3\BS\h2\booktest\models.py", line 15, in HeroInfo
hbook = models.ForeignKey(BookInfo)
**TypeError: init() missing 1 required positional argument: 'on_delete'


**

在django2.0后,定义外键和一对一关系的时候需要加on_delete选项,此参数为了避免两个表里的数据不一致问题,不然会报错:
TypeError: init() missing 1 required positional argument: 'on_delete'
解决方案:

class BookInfo(models.Model):    btitle = models.CharField(max_length=20)    bpub_date = models.DateTimeField()class HeroInfo(models.Model):    hname = models.CharField(max_length=20)    hgender = models.BooleanField()    hcontent = models.CharField(max_length=100)    hbook = models.ForeignKey('BookInfo', on_delete=models.CASCADE)

Django在根据models生成数据库表时报

转载于:https://blog.51cto.com/357712148/2330983

你可能感兴趣的文章
enum
查看>>
java自增的陷井
查看>>
Apache2.4版本环境下基于虚拟主机、ssl、用户控制
查看>>
要卖的四本书的封面
查看>>
Linux下puppet安装
查看>>
python笔记--集合
查看>>
系统吞吐量、TPS(QPS)、用户并发量、性能测试概念和公式
查看>>
区别Ruby的require,load,和include
查看>>
VMware view连接vCenter提示证书错误,无法连接vCenter服务器
查看>>
http协议
查看>>
cobbler快速部署
查看>>
医药吧手机版的发布
查看>>
threading
查看>>
Excel中始终保持标题行可见
查看>>
MySQL5解压缩版windows下安装配置应用总结
查看>>
VMware View环境的搭建--VMware View4.5架构介绍
查看>>
直接插入排序
查看>>
浅谈Java接口
查看>>
openstack issue 5
查看>>
网站群建设-->营造自己的网络圈品牌
查看>>