StudyBud
StudyBud copied to clipboard
Cannot create superuser from the command line!
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.
Comment line 12 in models.py
@chrispydev What does it do? Isn't overriding create_user
a better approach?
Hi guys I fixed this issue, please follow the instructions for a succesfully create super user without "delete" the username functionality:
- open models.py of base app.
- add to the REQUIRED_FIELDS the parameter 'username', line 13..
it should look like this:
REQUIRED_FIELDS = ['username',]
Hi guys I fixed this issue, please follow the instructions for a succesfully create super user without "delete" the username functionality:
- open models.py of base app.
- 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.
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
Hi guys I fixed this issue, please follow the instructions for a succesfully create super user without "delete" the username functionality:
- open models.py of base app.
- add to the REQUIRED_FIELDS the parameter 'username', line 13..
it should look like this:
REQUIRED_FIELDS = ['username',]
Yes it's worked for me
Hi guys I fixed this issue, please follow the instructions for a succesfully create super user without "delete" the username functionality:
- open models.py of base app.
- 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 = []