Opened 5 years ago

Closed 5 years ago

#30640 closed Bug (wontfix)

createsuperuser crashes when a custom user model contains required fields that overlap with default command options.

Reported by: Hasan Ramezani Owned by: Hasan Ramezani
Component: contrib.auth Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If we have a User model like this:

class User(AbstractUser):
    database = models.CharField(max_length=20)
  
    REQUIRED_FIELDS = ['database']

When we run python manage.py createsuperuser, we will get this error:
argparse.ArgumentError: argument --database: conflicting option string: --database.

Because of createsuperuser adds a --database option by default and also database is a required field of User model and command tries to add --database again.

Possible solution: add a prefix to fields which already added by createsupperuser.

Change History (2)

comment:1 by Hasan Ramezani, 5 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:2 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: assignedclosed
Summary: createsuperuser faces error when there is a custom user model with required field with the name same as command default optionscreatesuperuser crashes when a custom user model contains required fields that overlap with default command options.
Version: 2.2master

Thanks for the report, however even with a prefix we can encounter conflicts. I don't think that we should change this, user can always use DJANGO_SUPERUSER_DATABASE environment variable.

Note: See TracTickets for help on using tickets.
Back to Top