Issue with createsuperuser when implementing custom user model

天大地大妈咪最大 提交于 2019-11-30 19:22:05

Looking at the code for the management commands, it only prompts for fields in the user model's REQUIRED_FIELDS attribute (as well as username). That attribute contains email by default in AbstractBaseUser, but if you have overridden it - or not inherited from that model in the first place (which you should be doing) - then email will not be prompted, and not passed to the create_superuser method.

class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField('username', max_length=150, unique=True)
    email = models.EmailField('email address', unique=True, max_length = 255)
    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email']

For me above code simply solved problems.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!