的Django 1.9.7 我使用pyenv的virtualenv autoenvLookupError:應用程序「用戶」不具有「用戶」模式
我想要擴展用戶模型於是,我決定使用AbstractUser
(AbstractUser的class META
抽象=真,所以我不能讓表,但繼承類可以使右表??)
反正
(WEF是項目名稱) 我讓應用wef/users/models/__init__.py
from .user import User
在wef/users/models/user.py
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
phonenumber = models.CharField(
max_length = 11,
blank = True,
null = True
)
,我加入settings.py users
應用
INSTALLED_APPS = [
[...]
'users',
]
AUTH_USER_MODEL = 'users.User'
所以,我覺得當我makemigrations,遷移
Django會做模型關於用戶的表...
python wef/manage.py makemigrations users
它顯示錯誤
Traceback (most recent call last):
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/apps/config.py", line 163, in get_model
return self.models[model_name.lower()]
KeyError: 'user'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/management/base.py", line 398, in execute
self.check()
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/contrib/auth/checks.py", line 12, in check_user_model
cls = apps.get_model(settings.AUTH_USER_MODEL)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/apps/registry.py", line 197, in get_model
return self.get_app_config(app_label).get_model(model_name.lower())
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/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 'users' doesn't have a 'user' model.
我不明白爲什麼Django中無法找到users.User模型
,當我改變`AUTH_USER_MODEL = UserAAA」
它顯示錯誤(大寫字母更改爲小寫)
LookupError: App 'users' doesn't have a 'useraaa' model.
我無法找到我的問題 請人幫助我..ㅠ_ㅠ
是你的包真「模式」,而不是「模型」前有
from .user import User
? –哦對不起編輯我的錯誤,但它有相同的錯誤 –
請有人幫助我我真的需要任何人的幫助 –