向用户添加一个字段

Add one field to User

在我切换我的抽象用户后,我的 login/admin 开发页面无法使用 Debug = True 和 python manage.py runserver 进行签名。

虽然没有任何问题,但它可以在产品上运行。

登录开发时我得到

    Please enter a correct username and password. Note that both fields may be case-sensitive.

我还删除了我的 sqlite 数据库并在其上使用了 makemigrations。

我只想向用户添加一个字段,以便他们可以上传文件。

models.py

from django.db import models
from django.contrib.auth.models import AbstractUser

class Profile(AbstractUser):
    
    """ bio = models.TextField(max_length=500, blank=True)
    phone_number = models.CharField(max_length=12, blank=True)
    birth_date = models.DateField(null=True, blank=True) """
    avatar = models.ImageField(default='default.png', upload_to='users/', null=True, blank=True)

admin.py

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .models import Profile

class CustomUserAdmin(UserAdmin):
    pass

admin.site.register(Profile, CustomUserAdmin)

settings.py

# Extends default user with additional fields 
AUTH_USER_MODEL = 'pages.Profile'

当我使用迁移时

(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> python manage.py showmigrations
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
 [X] 0012_alter_user_first_name_max_length
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
pages
 [X] 0001_initial
sessions
 [X] 0001_initial

从尝试使用 Debug = True 登录的回溯

当登录开发时我得到

(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project>  python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
December 18, 2021 - 13:11:34
Django version 3.2.9, using settings 'portfolio.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[18/Dec/2021 13:11:46] "GET / HTTP/1.1" 200 753
Not Found: /favicon.ico
[18/Dec/2021 13:11:47] "GET /favicon.ico HTTP/1.1" 404 2716
[18/Dec/2021 13:11:49] "GET /accounts/login/ HTTP/1.1" 200 1215
[18/Dec/2021 13:11:50] "POST /accounts/login/ HTTP/1.1" 200 1369
[18/Dec/2021 13:12:03] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:12:22] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:12:30] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:12:36] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:12:43] "POST /accounts/login/ HTTP/1.1" 200 1368
[18/Dec/2021 13:13:15] "POST /accounts/login/ HTTP/1.1" 200 1368

删除数据库后运行python manage.py createsuperuser了吗?