2010-04-07 73 views
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'. 
+1

我複製你的代碼片段測試應用程序並運行syncdb,它的工作原理。我想可能還有其他一些你在這裏沒有提到的細節。 – satoru 2010-04-07 14:04:07

+0

當我運行測試時,我遇到了同樣的問題,但是在Syncdb中,以及在其工作的shell中保存對象。我仍然需要測試:-s。 – Fitoria 2010-11-17 15:44:29

+0

我不認爲你告訴我們所有的事情。您是否使用外部應用程序來增強用戶模型? – 2010-11-21 14:18:50

回答