0

下面是我的model.py

class CustomUser(AbstractUser):
    email = models.EmailField(unique=True, primary_key=True)

我通过为 AUTH_USER_MODEL 提供一个值来覆盖默认用户模型 setting.py

AUTH_USER_MODEL = 'home.CustomUser'

但是当我运行服务器时,我得到了AttributeError: 'CustomUser' object has no attribute 'model'

我的代码有什么问题?

我的django version = 4.0

完整的错误信息

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Hello world\Desktop\python\django\django3\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Hello world\Desktop\python\django\django3\lib\site-packages\django\core\management\commands\runserver.py", line 124, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\Hello world\Desktop\python\django\django3\lib\site-packages\django\core\management\base.py", line 438, in check
    all_issues = checks.run_checks(
  File "C:\Users\Hello world\Desktop\python\django\django3\lib\site-packages\django\core\checks\registry.py", line 77, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\Hello world\Desktop\python\django\django3\lib\site-packages\django\contrib\admin\checks.py", line 54, in check_admin_app
    errors.extend(site.check(app_configs))
  File "C:\Users\Hello world\Desktop\python\django\django3\lib\site-packages\django\contrib\admin\sites.py", line 95, in check
    if modeladmin.model._meta.app_config in app_configs:
AttributeError: 'CustomUser' object has no attribute 'model'

4

0 回答 0