gpt4 book ai didi

python - Django 查找错误 : App 'accounts' doesn't have a 'User' model

转载 作者:太空宇宙 更新时间:2023-11-03 14:51:04 27 4
gpt4 key购买 nike

从 Django 1.10 升级到 1.11 后,我几乎在做任何事情时都遇到了问题。我无法启动我的服务器,也无法运行 manage.py。

在升级之前,我没有收到这个问题,所以我不确定从那时起发生了什么变化会导致这个问题。

我也已经尝试删除数据库,没有任何改变。

我的 settings.py AUTH_USER_MODEL/INSTALLED_APPS:

AUTH_USER_MODEL = 'accounts.User'

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts.apps.AccountsConfig',
'forum.apps.ForumConfig',
]

我的用户模型:

class User(AbstractUser):
profile_picture = models.ImageField(null=True, blank=True)
birth_date = models.DateField(null=True, blank=True)

错误:

> Failed to get real commands on module "CsForum": python process died with code 
1: Traceback (most recent call last):
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\config.py", line 169, 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 "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\__init__.py", line 193, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\registry.py", line 205, in get_model
return app_config.get_model(model_name, require_ready=require_ready)
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\config.py", line 172, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'accounts' doesn't have a 'User' model.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2017.2.1\helpers\pycharm\_jb_manage_tasks_provider.py", line 25, in <module>
django.setup()
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\Elian\OneDrive\PycharmProjects\CsForum\accounts\models.py", line 1, in <module>
from django.contrib.auth.admin import UserAdmin
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\admin.py", line 7, in <module>
from django.contrib.auth.forms import (
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\forms.py", line 22, in <module>
UserModel = get_user_model()
File "C:\Users\Elian\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\__init__.py", line 198, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'accounts.User' that has not been installed

最佳答案

我已经设法解决了这个问题。问题是我的 CustomUserAdmin(管理页面中自定义字段的扩展 UserAdmin)在升级到 1.11 后不能再出现在我的 models.py 中。它现在在我的 admin.py 中,问题不再出现。

关于python - Django 查找错误 : App 'accounts' doesn't have a 'User' model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45783147/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com