2013-04-26 5 views
6
抽象ジャンゴ1.5.1

admin.logentry:</p>:「ユーザーが」私はカスタム認証モデルを作成するのいずれかがインストールされているされていないか、<p>

あるモデル<クラスのapi.models.User '>との関係を、持っています

ファイルAPI/models.py

from django.contrib.auth.models import BaseUserManager, AbstractUser 

class User(AbstractUser): 

    token = models.CharField(max_length=64, null=False, blank=False, help_text=_('Photo for carte'), unique=True) 
    updated_token = models.DateTimeField(auto_now_add=True, help_text=_('Create record')) 

    USERNAME_FIELD = 'email' 

    objects = MyUserManager() 

    def __unicode__(self): 
     return "пользователь: %s" % self.email 
    class Meta: 
     app_label = 'custom_auth' 

ファイルsettings.py

AUTH_USER_MODEL = 'custom_auth.User' 
..... 
INSTALLED_APPS = (
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'api', 
..... 
'south', 
'django.contrib.admin', 

0 ./manage.py syncdbの実行に

私はエラーを取得する:

admin.logentry: 'user' has a relation with model <class 'api.models.User'>, which has either not been installed or is abstract. 

どのようにこの問題を決めますか?

編集1 しようとしたコメント行としますsyncdbの実行:

'django.contrib.admin', 

syncdbの実行は、それが./manage.pyシェルでユーザーを作成しようとした 後に成功した

In [1]: from api.models import User 
In [2]: User.objects.create_superuser('[email protected]', 'test') 

とレシーブエラー:

DatabaseError: (1146, "Table 'app_name.custom_auth_user' doesn't exist") 

答えて

1

INSTALLED_APPSにあるapp_labelをクラスに設定する必要があります:app_label = 'api'(デフォルト)を設定するか、INSTALLED_APPS'custom_auth'を追加します(もちろん有効なアプリでなければなりません)。

Djangoの検証プロセスでは、get_modelとデフォルトでget_modelを使用して新しいUserクラスを取得しようとすると、インストールされているアプリケーションのモデルのみが返されます。あなたの現在のコードで確認することができます:あなたはINSTALLED_APPSにあなたのメタapp_labelの記述を追加するのを忘れ

>>> loading.get_model('custom_auth', 'user') 
>>> loading.get_model('custom_auth', 'user', only_installed=False) 
    > api.models.User 
0

# Application definition 

INSTALLED_APPS = (
    ... 
    'custom_auth', 
) 
+0

どれ例...? – Lucio

関連する問題