2014-01-30 31 views
0

我試圖使用django auth ldap(v1.1.7)與自定義用戶模型,雖然我有一切照顧,我仍遇到一個熟悉的錯誤消息,我只是不知道如何解決。django auth ldap與自定義用戶模型

運行python manage.py syncdb回報:

CommandError: One or more models did not validate: 
django_auth_ldap.testprofile: 'user' defines a relation with the model 'auth.Use 
r', which has been swapped out. Update the relation to point at settings.AUTH_US 
ER_MODEL. 

我的問題在這裏 - 我在哪裏可以找到django_auth_ldap.testprofile和更新的關係,來解決這個問題?

在此先感謝您的幫助。

LE:好的,有點googleing之後,我發現這個文件testprofile位於django_auth_ldap/models.py並獲得這樣的:我尋遍所有我的文件,發現該文件,修改爲指向settings.AUTH_USER_MODEL,仍然收到相同的錯誤。

任何人都可以請幫我解決這個問題嗎?

+0

您的自定義用戶模型在哪裏? settings.py中'AUTH_USER_MODEL'的值是多少? –

+0

我的自定義用戶模型位於項目/ models.py中,名爲CustomUser(項目是我的應用程序的名稱)。在設置中,AUTH_USER_MODEL的值是projects.CustomUser。當我將外鍵定義爲指向settings.AUTH_USER_MODEL時,所有其他關係都是固定的。 – Adelin

回答

0

這是the partdjango_auth_ldap的models.py -

class TestProfile(models.Model): 
    """ 
    A user profile model for use by unit tests. This has nothing to do with the 
    authentication backend itself. 
    """ 
    user = models.OneToOneField('auth.User') # <-- here is the trouble 
    is_special = models.BooleanField(default=False) 
    populated = models.BooleanField(default=False) 

,除非您解決這部分代碼並做Django documentation如說你不能修復它 -

Instead of referring to User directly, you should reference the user model using django.contrib.auth.get_user_model(). This method will return the currently active User model – the custom User model if one is specified, or User otherwise.

我不會推薦你自己修改第三方軟件包。如果可以,請向開發人員建議更改,或向他們發送拉取請求。一旦被接受,更新軟件包。

+0

這看起來很有希望 - 敬請期待結果 – Adelin

+0

很奇怪,現在我遇到了錯誤 'CommandError:一個或多個模型沒有驗證:'' django_auth_ldap.testprofile:「用戶」與模型設置的關係。 AUTH_USE' 'R_MODEL,其中有未安裝或是抽象的。' – Adelin

+0

設法讓它工作。最初我有'user = models.OneToOneField('settings.AUTH_USER_MODEL')',但是我把它改成了'user = get_user_model()',並且之後它工作正常。太糟糕了,我不得不忍受第三方軟件包的磨練。非常感謝您的幫助 – Adelin

相關問題