Python django.core.exceptions.impropertlyconfigured:AUTH_USER_MODEL指的是MODEL';app1.myUser';还没有安装
在我的Django项目中,我有一个名为app1的app 我在我的Python django.core.exceptions.impropertlyconfigured:AUTH_USER_MODEL指的是MODEL';app1.myUser';还没有安装,python,django,Python,Django,在我的Django项目中,我有一个名为app1的app 我在我的app1app的models.py中创建了一个名为myUser的模型,如下所示: from django.contrib.auth.models import User, AbstractUser class myUser(AbstractUser): is_student = models.BooleanField(default=False) is_teacher = models.BooleanField(d
app1
app的models.py中创建了一个名为myUser
的模型,如下所示:
from django.contrib.auth.models import User, AbstractUser
class myUser(AbstractUser):
is_student = models.BooleanField(default=False)
is_teacher = models.BooleanField(default=False)
class Student(models.Model):
user = models.OneToOneField(myUser, on_delete=models.CASCADE, primary_key=True)
roll = models.IntegerField(blank=True)
AUTH_USER_MODEL = 'app1.myUser'
我还在settings.py中设置AUTH\u USER\u MODEL
,如下所示:
from django.contrib.auth.models import User, AbstractUser
class myUser(AbstractUser):
is_student = models.BooleanField(default=False)
is_teacher = models.BooleanField(default=False)
class Student(models.Model):
user = models.OneToOneField(myUser, on_delete=models.CASCADE, primary_key=True)
roll = models.IntegerField(blank=True)
AUTH_USER_MODEL = 'app1.myUser'
这里,admin.site.register(myUser)
也在admin.py中完成,而app1
也安装在installed\u APPS
列表中的settings.py。现在,当我使用migrate或runserver时,我在控制台中遇到以下错误:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "G:\Python\lib\site-packages\django\apps\config.py", line 178, in get_model
return self.models[model_name.lower()]
KeyError: 'myuser'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "G:\Python\lib\site-packages\django\contrib\auth\__init__.py", line 156, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "G:\Python\lib\site-packages\django\apps\registry.py", line 210, in get_model
return app_config.get_model(model_name, require_ready=require_ready)
File "G:\Python\lib\site-packages\django\apps\config.py", line 180, in get_model
raise LookupError(
LookupError: App 'app1' doesn't have a 'myUser' model.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "G:\Python\lib\threading.py", line 932, in _bootstrap_inner
self.run()
self._target(*self._args, **self._kwargs)
File "G:\Python\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "G:\Python\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "G:\Python\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "G:\Python\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "G:\Python\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "G:\Python\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "G:\Python\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "G:\Python\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "G:\Python\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\Project\django\hackathon practice\prjct1.1 User model\app1\models.py", line 3, in <module>
from django.contrib.auth.forms import UserCreationForm
File "G:\Python\lib\site-packages\django\contrib\auth\forms.py", line 20, in <module>
UserModel = get_user_model()
File "G:\Python\lib\site-packages\django\contrib\auth\__init__.py", line 160, in get_user_model
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'app1.myUser' that has not been installed
使用StatReloader监视文件更改
线程django主线程中出现异常:
回溯(最近一次呼叫最后一次):
get\U模型中的文件“G:\Python\lib\site packages\django\apps\config.py”,第178行
返回self.models[model_name.lower()]
KeyError:“我的用户”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“G:\Python\lib\site packages\django\contrib\auth\\uuuuu init\uuuuuu.py”,第156行,在get\u user\u模型中
返回django_apps.get_model(settings.AUTH_USER_model,require_ready=False)
get\U模型中的文件“G:\Python\lib\site packages\django\apps\registry.py”,第210行
返回app\u config.get\u model(model\u name,require\u ready=require\u ready)
文件“G:\Python\lib\site packages\django\apps\config.py”,第180行,在get\u模型中
升起LookupError(
LookupError:应用程序“app1”没有“myUser”模型。
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“G:\Python\lib\threading.py”,第932行,在_bootstrap_inner中
self.run()
自我目标(*自我参数,**自我参数)
文件“G:\Python\lib\site packages\django\utils\autoreload.py”,第53行,在包装器中
fn(*args,**kwargs)
文件“G:\Python\lib\site packages\django\core\management\commands\runserver.py”,第109行,在内部运行
autoreload.raise\u last\u异常()
文件“G:\Python\lib\site packages\django\utils\autoreload.py”,第76行,在raise\u last\u异常中
raise_异常[1]
文件“G:\Python\lib\site packages\django\core\management\\uuuuu init\uuuuuu.py”,第357行,在execute中
自动加载检查错误(django.setup)()
文件“G:\Python\lib\site packages\django\utils\autoreload.py”,第53行,在包装器中
fn(*args,**kwargs)
文件“G:\Python\lib\site packages\django\\uuuu init\uuuuuu.py”,第24行,在安装程序中
应用程序。填充(设置。已安装的应用程序)
文件“G:\Python\lib\site packages\django\apps\registry.py”,第114行,在“填充”中
app_config.import_models()
文件“G:\Python\lib\site packages\django\apps\config.py”,第211行,在import\u模型中
self.models\u module=导入模块(models\u module\u name)
文件“G:\Python\lib\importlib\\uuuuu init\uuuuuu.py”,第127行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
文件“”,第1014行,在\u gcd\u导入中
文件“”,第991行,在“查找”和“加载”中
文件“”,第975行,在“查找”和“加载”中解锁
文件“”,第671行,在\u加载\u解锁
exec_模块中第783行的文件“”
文件“”,第219行,在“调用”中,删除了“帧”
文件“D:\Project\django\hackathon practice\prjct1.1 User model\app1\models.py”,第3行,在
从django.contrib.auth.forms导入UserCreationForm
文件“G:\Python\lib\site packages\django\contrib\auth\forms.py”,第20行,在
UserModel=get\u user\u model()
文件“G:\Python\lib\site packages\django\contrib\auth\\uuuuuu init\uuuuuuu.py”,第160行,在get\u user\u模型中
提高配置不当(
django.core.exceptions.ImpropertlyConfigured:身份验证用户模型引用了尚未安装的模型“app1.myUser”
如何解决此问题?发生的错误有以下来源:
File "D:\Project\django\hackathon practice\prjct1.1 User model\app1\models.py", line 3, in <module> from django.contrib.auth.forms import UserCreationForm
文件“D:\Project\django\hackathon practice\prjct1.1 User model\app1\models.py”,第3行,从django.contrib.auth.forms导入UserCreationForm
在model.py中声明用户之前,不要导入UserCreationForm!您可以创建一个新文件forms.py,也可以在model.py中定义用户后导入UserCreationForm。您可以使用
python manage.py shell
打开django shell并从django.apps运行导入应用程序吗
并共享输出?python manage.py shell给出错误,例如…..keyrerror:“myuser”您是否在model.py
文件或models.py
文件中创建了模型?它应该是models.py
它在models中。py@KanchonGharami在settings.py
中注释出AUTH\u USER\u MODEL='app1.myUser'
,并执行在shell中删除这些命令。