4
当试图用下面的模型来执行syncdb:Django的用户M2M关系
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'.
我复制你的代码片段测试应用程序并运行syncdb,它的工作原理。我想可能还有其他一些你在这里没有提到的细节。 – satoru 2010-04-07 14:04:07
当我运行测试时,我遇到了同样的问题,但是在Syncdb中,以及在其工作的shell中保存对象。我仍然需要测试:-s。 – Fitoria 2010-11-17 15:44:29
我不认为你告诉我们所有的事情。您是否使用外部应用程序来增强用户模型? – 2010-11-21 14:18:50