gpt4 book ai didi

python - Django 用户 M2M 关系

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:21 24 4
gpt4 key购买 nike

尝试使用以下模型同步数据库时:

class Contact(models.Model):
user_from = models.ForeignKey(User,related_name='from_user')
user_to = models.ForeignKey(User, related_name='to_user')

class Meta:
unique_together = (('user_from', 'user_to'),)

User.add_to_class('following', models.ManyToManyField('self', through=Contact, related_name='followers', symmetrical=False))

我收到以下错误:

Error: One or more models did not validate:
auth.user: Accessor for m2m field 'following' clashes with related m2m field 'User.followers'. Add a related_name argument to the definition for 'following'.

auth.user: Reverse query name for m2m field 'following' clashes with related m2m field 'User.followers'. Add a related_name argument to the definition for 'following'.
auth.user: The model User has two manually-defined m2m relations through the model Contact, which is not permitted. Please consider using an extra field on your intermediary model instead.

auth.user: Accessor for m2m field 'following' clashes with related m2m field 'User.followers'. Add a related_name argument to the definition for 'following'.

auth.user: Reverse query name for m2m field 'following' clashes with related m2m field 'User.followers'. Add a related_name argument to the definition for 'following'.

最佳答案

请参阅 Carl 对此问题的回答 Django: Model name clash

关于python - Django 用户 M2M 关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2592187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com