2016-07-29 88 views
1

enter image description hereDjango的:LookupError:應用程序「沒有一個‘模型’模型

我通過https://bixly.com/blog/awesome-forms-django-crispy-forms/工作,試圖建立使用Django香脆形式的引導3形式。

在APP1/models.py,我已經建立了自己的狀態:

from django.db import models 
from django.contrib.auth.models import User 
from django.contrib.auth.models import AbstractUser 
from django import forms 


class User(AbstractUser): 

    # Address 
    contact_name = models.CharField(max_length=50) 
    contact_address = models.CharField(max_length=50) 
    contact_email = models.CharField(max_length=50) 
    contact_phone = models.CharField(max_length=50) 
    ...... 

請注意,我還沒有創建任何數據庫表呢。在這個階段我不需要他們。我只是想讓表格工作。當我跑這個我得到:

Performing system checks... 

Unhandled exception in thread started by <function wrapper at 0x02B63EF0> 
Traceback (most recent call last): 
    File "C:\lib\site-packages\django\utils\autoreload.py", line 222, in wrapper 
    fn(*args, **kwargs) 
    File "C:\lib\site-packages\django\core\management\commands\runserver.py", line 105, in inner_run 
    self.validate(display_num_errors=True) 
    File "C:\lib\site-packages\django\core\management\base.py", line 362, in validate 
    return self.check(app_configs=app_configs, display_num_errors=display_num_errors) 
    File "C:\lib\site-packages\django\core\management\base.py", line 371, in check 
    all_issues = checks.run_checks(app_configs=app_configs, tags=tags) 
    File "C:\lib\site-packages\django\core\checks\registry.py", line 59, in run_checks 
    new_errors = check(app_configs=app_configs) 
    File "C:\lib\site-packages\django\contrib\auth\checks.py", line 12, in check_user_model 
    cls = apps.get_model(settings.AUTH_USER_MODEL) 
    File "C:\lib\site-packages\django\apps\registry.py", line 202, in get_model 
    return self.get_app_config(app_label).get_model(model_name.lower()) 
    File "C:\lib\site-packages\django\apps\config.py", line 166, in get_model 
    "App '%s' doesn't have a '%s' model." % (self.label, model_name)) 
LookupError: App 'app1' doesn't have a 'models' model. 

我該如何解決這個問題?

回答

5

AUTH_USER_MODEL設置的格式應該是<app name>.<model>。您的型號名稱爲User,不model,所以你的設置應該是:

AUTH_USER_MODEL = 'app1.User' 

你也應該從models.py刪除以下User進口。您只需要導入AbstractUser

from django.contrib.auth.models import User 
+0

謝謝,這工作! – user61629

相關問題