StudyBud icon indicating copy to clipboard operation
StudyBud copied to clipboard

Cannot create superuser from the command line!

Open Gr3Kidd3r opened this issue 3 years ago • 7 comments

Running method of creating superusers according to Django docs result in the following stacktrace:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "mypath/study-bud/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "mypath/study-bud/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "mypath/study-bud/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "mypath/study-bud/.venv/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
    return super().execute(*args, **options)
  File "mypath/study-bud/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "mypath/study-bud/.venv/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 189, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
TypeError: create_superuser() missing 1 required positional argument: 'username'

It has to do with not implementing the BaseUserManager methods correctly as your custom model differs.

I did a quick tweak locally and it works fine.

Gr3Kidd3r avatar Dec 16 '21 23:12 Gr3Kidd3r

Comment line 12 in models.py

chrispydev avatar Jan 13 '22 09:01 chrispydev

@chrispydev What does it do? Isn't overriding create_user a better approach?

Gr3Kidd3r avatar Jan 16 '22 00:01 Gr3Kidd3r

Hi guys I fixed this issue, please follow the instructions for a succesfully create super user without "delete" the username functionality:

  1. open models.py of base app.
  2. add to the REQUIRED_FIELDS the parameter 'username', line 13..

it should look like this:

REQUIRED_FIELDS = ['username',]

mgonzalezm-dev avatar Mar 02 '22 17:03 mgonzalezm-dev

Hi guys I fixed this issue, please follow the instructions for a succesfully create super user without "delete" the username functionality:

  1. open models.py of base app.
  2. add to the REQUIRED_FIELDS the parameter 'username', line 13..

it should look like this:

REQUIRED_FIELDS = ['username',]

I did the same, it helped with creating supersuper but now i am not able to register from the frontend side.

Amisha-here avatar Apr 21 '22 09:04 Amisha-here

type this in the cmd/terminal (env) $ python manage.py shell This should bring up the shell command prompt as follows:

                  Python 3.7.2 (default, Mar 27 2019, 08:44:46) 
                  [GCC 6.3.0 20170516] on linux
                  Type "help", "copyright", "credits" or "license" for more information.
                  (InteractiveConsole)
                  >>>

Then execute the following:

                  >>> from django.contrib.auth import get_user_model
                  >>> User = get_user_model()
                  >>> user = User.objects.get(username='dennis')
                  >>> user.set_password('new password')
                  >>> user.save()
                  >>> exit()

after this login as admin: admin url - http://127.0.0.1:8000/admin/login/?next=/admin/
login details for login in :
[email protected] new password then you can change the other details later on

dev-sheikh-ali avatar Apr 23 '22 18:04 dev-sheikh-ali

Hi guys I fixed this issue, please follow the instructions for a succesfully create super user without "delete" the username functionality:

  1. open models.py of base app.
  2. add to the REQUIRED_FIELDS the parameter 'username', line 13..

it should look like this:

REQUIRED_FIELDS = ['username',]

Yes it's worked for me

belhaddadmohamed avatar Sep 21 '23 14:09 belhaddadmohamed

Hi guys I fixed this issue, please follow the instructions for a succesfully create super user without "delete" the username functionality:

  1. open models.py of base app.
  2. add to the REQUIRED_FIELDS the parameter 'username', line 13..

it should look like this: REQUIRED_FIELDS = ['username',]

I did the same, it helped with creating supersuper but now i am not able to register from the frontend side.

Now after you create a super user you can turn the as an empty list ---> REQUIRED_FIELDS = []

belhaddadmohamed avatar Sep 21 '23 14:09 belhaddadmohamed