Django错误消息“将相关名称参数添加到定义” [英] Django error message "Add a related_name argument to the definition"

查看:111
本文介绍了Django错误消息“将相关名称参数添加到定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

D:\zjm_code\basic_project>python manage.py syncdb
Error: One or more models did not validate:
topics.topic: Accessor for field 'content_type' clashes with related field 'Cont
entType.topic_set'. Add a related_name argument to the definition for 'content_t
ype'.
topics.topic: Accessor for field 'creator' clashes with related field 'User.crea
ted_topics'. Add a related_name argument to the definition for 'creator'.
topics.topic: Reverse query name for field 'creator' clashes with related field
'User.created_topics'. Add a related_name argument to the definition for 'creato
r'.
topicsMap.topic: Accessor for field 'content_type' clashes with related field 'C
ontentType.topic_set'. Add a related_name argument to the definition for 'conten
t_type'.
topicsMap.topic: Accessor for field 'creator' clashes with related field 'User.c
reated_topics'. Add a related_name argument to the definition for 'creator'.
topicsMap.topic: Reverse query name for field 'creator' clashes with related fie
ld 'User.created_topics'. Add a related_name argument to the definition for 'cre
ator'.


推荐答案

你有一些django无法使用的外键为...生成唯一的名称。

You have a number of foreign keys which django is unable to generate unique names for.

您可以通过在模型中的foreignkey字段定义中添加related_name参数来帮助您。
例如:

You can help out by adding "related_name" arguments to the foreignkey field definitions in your models. Eg:

content_type = ForeignKey(Topic, related_name='topic_content_type')

有关详情,请参阅这里。
http:// docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name

See here for more. http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name

这篇关于Django错误消息“将相关名称参数添加到定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆