Unable to create superuser after creating CustomUser

After creating Custom user when i tried to create a superuser it gave error

TypeError: UserManager.create_superuser() missing 1 required positional argument: ‘username’

Then after creating CustomUserManager its showing

Expression of type “CustomUserManager” is incompatible with declared type “UserManager[Self@AbstractUser]”
“CustomUserManager” is incompatible with “UserManager[Self@AbstractUser]”

Expression of type "CustomUserManager" is incompatible with declared type "UserManager[Self@AbstractUser]"
  "CustomUserManager" is incompatible with "UserManager[Self@AbstractUser]"

class CustomUserManager(BaseUserManager):
    def create_user(self, email, password=None, **extra_fields):
        if not email:
            raise ValueError('The Email field must be set')
        email = self.normalize_email(email)
        user = self.model(email=email, **extra_fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, email, password=None, **extra_fields):
        extra_fields.setdefault('is_staff', True)
        extra_fields.setdefault('is_superuser', True)
        return self.create_user(email, password, **extra_fields)


class CustomUser(AbstractUser, PermissionsMixin):
    username = None
    email = models.EmailField(unique=True)  

    daily_reminders = models.IntegerField(default=0)
    start_at = models.TimeField(null=True, blank=True)
    end_at = models.TimeField(null=True, blank=True)
    notification_status = models.IntegerField(null=True, blank=True)
    device_type = models.CharField(choices=DIV_CHOICES, max_length=10, null=True, blank=True)
    device_token = models.CharField(max_length=255, null=True, blank=True)
    categories = models.JSONField(default=list, null=True, blank=True)
    

    USERNAME_FIELD = 'email'  
    REQUIRED_FIELDS = []  
    
    objects = CustomUserManager()

    def __str__(self):
        return self.email

I BaseUserManager imported

from django.contrib.auth.base_user import BaseUserManager

but still showing error

Check this article to understand better the Custom User Model : Creating a Custom User Model in Django | TestDriven.io

You should inherit from UserManager like so:

from django.contrib.auth.models import UserManager

class CustomUserManager(UserManager):
1 Like