Django一对多关系模型Add a related_name argument to the definit的错误
下面是一对多的关系模型
class Cats(models.Model):
#...
catnum = models.IntegerField(unique=True)
#...
class Items(models.Model):
catid = models.ForeignKey(Cats, to_field='catnum', db_column='catid')
#...
Unhandled exception in thread started by
Traceback (most recent call last):
File “c:/python27/lib/site-packages/django/core/management/commands/runserver.py”, line 48, in inner_run
self.validate(display_num_errors=True)
File “c:/python27/lib/site-packages/django/core/management/base.py”, line 253, in validate
raise CommandError(“One or more models did not validate:/n%s” % error_text)
django.core.management.base.CommandError: One or more models did not validate:
beauty.items: Reverse query name for field ‘catid’ clashes with field ‘Cats.items’. Add a related_name argument to the definit
ion for ‘catid’.
发生的错误大概意思是要增加一个related_name参数,所以Items模型改为
class Items(models.Model):
catid = models.ForeignKey(Cats, to_field='catnum', db_column='catid', related_name='catid')
#...
大数据培训、人工智能培训、Python培训、大数据培训机构、大数据培训班、数据分析培训、大数据可视化培训,就选光环大数据!光环大数据,聘请专业的大数据领域知名讲师,确保教学的整体质量与教学水准。讲师团及时掌握时代潮流技术,将前沿技能融入教学中,确保学生所学知识顺应时代所需。通过深入浅出、通俗易懂的教学方式,指导学生更快的掌握技能知识,成就上万个高薪就业学子。 更多问题咨询,欢迎点击------>>>>在线客服!