#28461: Can't create superuser with ForeignKey required field ----------------------------------------+------------------------ Reporter: Kirill B. | Owner: nobody Type: Bug | Status: new Component: contrib.auth | Version: 1.11 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | ----------------------------------------+------------------------ These are my models:
{{{ from uuid import uuid4 from django.contrib.auth.models import AbstractUser from django.db import models class Company(models.Model): name = models.CharField(max_length=64, primary_key=True) class User(AbstractUser): uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4) company = models.ForeignKey(Company) REQUIRED_FIELDS = ['email', 'company'] }}} When I run `manage.py createsuperuser` I got this result: {{{ Username: superuser Email address: t...@example.com Company (Company.name): TEST Password: Password (again): Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/core/management/__init__.py", line 363, in execute_from_command_line utility.execute() File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/core/management/__init__.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/contrib/auth/management/commands/createsuperuser.py", line 63, in execute return super(Command, self).execute(*args, **options) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/contrib/auth/management/commands/createsuperuser.py", line 183, in handle self.UserModel._default_manager.db_manager(database).create_superuser(**user_data) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/contrib/auth/models.py", line 170, in create_superuser return self._create_user(username, email, password, **extra_fields) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/contrib/auth/models.py", line 151, in _create_user user = self.model(username=username, email=email, **extra_fields) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/contrib/auth/base_user.py", line 68, in __init__ super(AbstractBaseUser, self).__init__(*args, **kwargs) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/db/models/base.py", line 554, in __init__ _setattr(self, field.name, rel_obj) File "/Users/ookami/venv/swportal/lib/python3.5/site- packages/django/db/models/fields/related_descriptors.py", line 216, in __set__ self.field.remote_field.model._meta.object_name, ValueError: Cannot assign "'TEST'": "User.company" must be a "Company" instance. }}} -- Ticket URL: <https://code.djangoproject.com/ticket/28461> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.cc7746560d22444775b5d5b940137cb9%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.