#29019: Superuser creation for custom user model fails with required ManyToMany
field
----------------------------------------+-----------------------------
Reporter: James Kirsop | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 2.0
Severity: Normal | Keywords: user custom
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+-----------------------------
I've defined a custom user model with a ManyToMany field.
When running `manage.py createsuperuser` I receive the following error
after entering the user's email address:
{{{
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/jkirsop/Development/artemis/venv/lib/python3.6/site-
packages/django/core/management/__init__.py", line 371, in
execute_from_command_line
utility.execute()
File "/Users/jkirsop/Development/artemis/venv/lib/python3.6/site-
packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/jkirsop/Development/artemis/venv/lib/python3.6/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/jkirsop/Development/artemis/venv/lib/python3.6/site-
packages/django/contrib/auth/management/commands/createsuperuser.py", line
59, in execute
return super().execute(*args, **options)
File "/Users/jkirsop/Development/artemis/venv/lib/python3.6/site-
packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/Users/jkirsop/Development/artemis/venv/lib/python3.6/site-
packages/django/contrib/auth/management/commands/createsuperuser.py", line
133, in handle
) if field.remote_field else '',
AttributeError: 'ManyToManyRel' object has no attribute 'field_name'
}}}
**Models**
My custom user model is defined as such (relevant pieces only included):
{{{
class OrgUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
orgs = models.ManyToManyField(Organisation)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['orgs']
objects = OrgUserManager()
}}}
and Organisations
{{{
class Organisation(models.Model):
name = models.CharField(max_length=60)
def __str__(self):
return self.name
}}}
It seems that if I remove the need for the Orgs to be a `REQUIRED_FIELD`
the issue goes away. However, it's central to my project and needs to be
defined on every user.
Happy to update the ticket with any other code snippets if required.
--
Ticket URL: <https://code.djangoproject.com/ticket/29019>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/054.a905898107b3fb1c61eaac5a7f66ceec%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.