您好,欢迎访问一九零五行业门户网

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')
   #...
其它类似信息

推荐信息