Django用户M2M关系

时间:2010-04-07 12:01:21

标签: python django django-models

尝试使用以下型号同步dbdb时:

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'.

1 个答案:

答案 0 :(得分:0)

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