简体   繁体   中英

Django creating super user error: AttributeError: 'ProfileManager' object has no attribute 'create_superuser'

Hi I am trying to create a superuser, however, after I added my own ProfileManager I get the error:

AttributeError: 'ProfileManager' object has no attribute 'create_superuser'

But my issue is should BaseUserManager already have this method? I cannot find a why to inherit the create_superuser method.

My manager is:

class ProfileManager(BaseUserManager):
      pass

And my model is:

class Profile(AbstractUser):
      
      objects = ProfileManager()

Thanks for all the help in advance!

BaseUserManager class does not have create_superuser nor create_user , these methods are implemented in UserManager

Which is also documented in customizing authentication documentation

If your user model defines username, email, is_staff, is_active, is_superuser, last_login, and date_joined fields the same as Django's default user, you can install Django's UserManager; however, if your user model defines different fields, you'll need to define a custom manager that extends BaseUserManager providing two additional methods:

  • create_user

  • create_superuser

So you don't need to set objects attribute nor override anything as AbstractUser sets objects attribute to

 objects = UserManager()

No, BaseUserManager doesn't have that method, but UserManager does




class ProfileManager():
    pass

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