Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create superuser from the command line! #9

Open
Gr3Kidd3r opened this issue Dec 16, 2021 · 7 comments
Open

Cannot create superuser from the command line! #9

Gr3Kidd3r opened this issue Dec 16, 2021 · 7 comments

Comments

@Gr3Kidd3r
Copy link

Gr3Kidd3r commented Dec 16, 2021

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.

@chrispydev
Copy link

Comment line 12 in models.py

@Gr3Kidd3r
Copy link
Author

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

@mgonzalezm-dev
Copy link

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',]

@Amisha-here
Copy link

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.

@dev-sheikh-ali
Copy link

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

@belhaddadmohamed
Copy link

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
Copy link

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 = []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants