Manager isn't available

My Register view is like below.

class UserRegisterView( FormView ):
    template_name = 'register.html'
    form_class = UserCreationForm
    redirect_authenticated_user = True
    success_url = reverse_lazy('dashboard')  # name of URL     

    def form_valid( self, form ):
        user =
        if user is not None:
            login( self.request, user )
        return super( UserRegisterView, self ).form_valid( form )
    def get( self, *args, **kwargs ):
        if self.request.user.is_authenticated:
            return redirect('register')
        return super( UserRegisterView, self ).get( *args, **kwargs )

My model is like below.

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

# Create your models here.

class User(AbstractUser):
        ('M', 'Male'),
        ('F', 'Female'),
        ('O', 'Other'),

    USER_TYPE = (
        ('S', 'Super Admin'),
        ('A', 'Admin'),
        ('P', 'Patient'),
        ('D', 'Doctor'),
        ('U', 'User'),

    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    date_of_birth = models.DateField(null=True, blank=True )
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    user_type = models.CharField(max_length=1, choices=USER_TYPE)
    username = models.EmailField(unique=True)
    email = models.EmailField(unique=True)
    phone = models.CharField(max_length=15, blank=True, null=True)
    address = models.TextField(blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    active = models.BooleanField(default=True)


    def __str__(self):
        return f"{self.first_name} {self.last_name}"

I am getting error Manager isn't available; 'auth.User' has been swapped for 'hospital.User'

Can you also provide your form: UserCreationForm?
It looks like you’re trying to use the form from django.contrib.auth that uses the auth.User class.

1 Like

When using a custom user model you cannot use the system-provided UserCreationForm. You need to use a form created for your model.

1 Like