简体   繁体   中英

Extending AbstractUser in django

I was trying to subclass AbstractUser and stuck in an error on running migrate, and makemigrations says No changes detected

django.db.utils.ProgrammingError: relation "auth_group" does not exist

model:

class SubClient(AbstractUser):
    client_id = models.ForeignKey(Client)
    phone = models.CharField(max_length=15)

added in settings.py:

AUTH_USER_MODEL = 'myadmin.SubClient'

This error means the auth_group table does not exist in your database. Which means you did not run Django's migration files (python files describing database structure and its changes over time).

As you have your own models, you first need to create migration files for them by running python manage.py makemigrations .

Then run python manage.py migrate to run all migrations (Django's + yours), this will create all database tables (including auth_croup ).

Read the doc to lean more about migrations.

when using AbstractUser could i use django's user's builtin password-reset workflow such as password-reset, password-reset-done etc. the reason i am asking is that i extended user model using AbstractUser but these built-in function not working and i do not get any error but it redirects me to search page and there is no documentation on the internet regarding this issue:

from django.contrib.auth import views as auth_views

path('password-reset/', auth_views.PasswordResetView.as_view(template_name='accounts/password_reset.html'),
         name='password-reset'),
    path('password-reset/done/',
         auth_views.PasswordResetDoneView.as_view(template_name='accounts/password_reset_done.html'),
         name='password-reset-done'),
    path('password-reset-confirm/<uidb65>/<token>/',
         auth_views.PasswordResetConfirmView.as_view(template_name='accounts/password_reset_confirm.html'),
         name='password-reset-confirm'),
    path('password-reset-complete/s',
         auth_views.PasswordResetCompleteView.as_view(template_name='accounts/password_reset_complete.html'),
         name='password-reset-complete')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM