成都创新互联网站制作重庆分公司

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'

创新互联专注于蕉城企业网站建设,响应式网站,购物商城网站建设。蕉城网站建设公司,为蕉城等地区提供建站服务。全流程按需制作网站,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

**
在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生成数据库表时报

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻标题:Django在根据models生成数据库表时报-创新互联
链接URL:http://cxhlcq.com/article/dhecge.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部