gpt4 book ai didi

django - 查找错误 : App 'users' doesn't have a 'user' model

转载 作者:行者123 更新时间:2023-12-01 15:40:54 24 4
gpt4 key购买 nike

Django 1.9.7
我正在使用 pyenv virtualenv autoenv

我想扩展用户模型,所以我决定使用 AbstractUser
(AbstractUser的class METAabstract = True,所以我不能做表,但是继承类可以做表,对吧??)

无论如何

(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
)

我添加 users settings.py 中的应用程序
INSTALLED_APPS = [
[...]
'users',
]

AUTH_USER_MODEL = 'users.User'

所以,我想当我进行迁移时,迁移

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.

我找不到我的问题
请有人帮助我..ㅠ_ㅠ

最佳答案

我认为您已经创建了数据库架构。来自 Django documentation :

Changing AUTH_USER_MODEL has a big effect on your database structure. It changes the tables that are available, and it will affect the construction of foreign keys and many-to-many relationships. If you intend to set AUTH_USER_MODEL, you should set it before creating any migrations or running manage.py migrate for the first time.

Changing this setting after you have tables created is not supported by makemigrations and will result in you having to manually fix your schema, port your data from the old user table, and possibly manually reapply some migrations.

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

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