Reseting the Super User Password

In a project gone wrong, I managed to walk away from my project for a week or two and when I returned my usual password for the super user failed. I went to stack overflow and found this great article on how to do it. authentication - How to reset Django admin password? - Stack Overflow

When I attempted the command however I received this error message.

I have tried to create another super user but it is giving me the same error.

Traceback (most recent call last):
  File "/Users/andrewstribling/Desktop/Programming/projects/django/news/manage.py", line 22, in <module>
    main()
  File "/Users/andrewstribling/Desktop/Programming/projects/django/news/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/contrib/auth/management/commands/changepassword.py", line 45, in handle
    u = UserModel._default_manager.using(options["database"]).get(
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/models/query.py", line 633, in get
    num = len(clone)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/models/query.py", line 380, in __len__
    self._fetch_all()
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/models/query.py", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/models/query.py", line 91, in __iter__
    results = compiler.execute_sql(
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
    return super().execute(query, params)
django.db.utils.OperationalError: no such table: accounts_customuser

Clear all the previous migrations, drop the db and re-create it. Then run makemigrations and migrate.

1 Like

(base) andrewstribling@Andrews-MBP news % python manage.py changepassword andrewstribling
CommandError: user ‘andrewstribling’ does not exist

(base) andrewstribling@Andrews-MBP news % python manage.py createsuperuser strikeouts27
usage: manage.py createsuperuser [-h] [–username USERNAME] [–noinput] [–database DATABASE] [–email EMAIL] [–version]
[-v {0,1,2,3}] [–settings SETTINGS] [–pythonpath PYTHONPATH] [–traceback] [–no-color]
[–force-color] [–skip-checks]
manage.py createsuperuser: error: unrecognized arguments: strikeouts27

I have attempted to reset the password and I have attempted to create a new superuser and have gotten pushback

When you created andrewstribling this superuser, have you created model CustomUser in accounts app?
Because it seems you have created andrewstribling this user with django User model and then afterwards created CustomUser in accounts app.

in order to solve this error I needed to run migrations.

In order to solve the username problem I had to run:
python manage.py createsuperuser

and than it would prompt me for a password.