开发者

Django User M2M relationship

When trying to syncdb with the following models:

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))

I get the following error:

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 'U开发者_运维技巧ser.followers'. Add a related_name argument to the definition for 'following'.


See Carl's answer to this question Django: Model name clash

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜