网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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

D:\TOOL\PycharmProjects\python3\BS\h3>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 15, in
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 "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "D:\TOOL\PycharmProjects\python3\BS\h3\booktest\models.py", line 11, in
class HeroInfo(models.Model):
File "D:\TOOL\PycharmProjects\python3\BS\h3\booktest\models.py", line 15, in HeroInfo
hbook = models.ForeignKey(BookInfo)
**TypeError: init() missing 1 required positional argument: 'on_delete'

创新互联网站建设公司,提供成都网站制作、成都网站设计、外贸营销网站建设,网页设计,建网站,PHP网站建设等专业做网站服务;可快速的进行网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,是专业的做网站团队,希望更多企业前来合作!


**
在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)

https://www.cnblogs.com/phyger/p/8035253.html
Django在根据models生成数据库表时报


标题名称:Django在根据models生成数据库表时报
分享地址:http://bjjierui.cn/article/jjpdje.html

其他资讯