Nicholas Sabin
Nicholas Sabin

Reputation: 23

How do I create a Django superuser in ssh?

I am deploying Django with PostgreSQL in Azure for a school project, per this tutorial. I am working with Django 2.1.2, and Python 3.7.5.

In the "Run Database Migrations" step of the tutorial, I am instructed to open an SSH session and run the following commands:

cd site/wwwroot
source /antenv/bin/activate
python manage.py migrate
python manage.py createsuperuser

When I run the 'createsuperuser' command, I expect a prompt for a username, email address, and password, but I am not prompted for any of these. Instead, the SSH session prompts me for another input, as below:

enter image description here

As such, I am unable to log in to my Django installation. When I attempt a login, I receive the following error message:

ProgrammingError at /admin/login/

The traceback is at the end of this message.

I expect to be able to create a superuser in Django, and use that superuser account to configure the app. Instead, I receive the ProgrammingError message and am unable to proceed.

Any help would be gratefully received. I have Googled the various error message, searched StackOverflow, and searched YouTube for tutorials, and I have reached a roadblock.

Environment:


Request Method: POST
Request URL: http://nicholas-blog.azurewebsites.net/admin/login/?next=/admin/

Django Version: 2.1.2
Python Version: 3.7.5
Installed Applications:
['polls.apps.PollsConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

The above exception (relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
                                                             ^
) was the direct cause of the following exception:

File "/antenv/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/antenv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "/antenv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/antenv/lib/python3.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/contrib/admin/sites.py" in login
  398.         return LoginView.as_view(**defaults)(request)

File "/antenv/lib/python3.7/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  76.             return view(request, *args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/contrib/auth/views.py" in dispatch
  61.         return super().dispatch(request, *args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/views/generic/edit.py" in post
  141.         if form.is_valid():

File "/antenv/lib/python3.7/site-packages/django/forms/forms.py" in is_valid
  185.         return self.is_bound and not self.errors

File "/antenv/lib/python3.7/site-packages/django/forms/forms.py" in errors
  180.             self.full_clean()

File "/antenv/lib/python3.7/site-packages/django/forms/forms.py" in full_clean
  382.         self._clean_form()

File "/antenv/lib/python3.7/site-packages/django/forms/forms.py" in _clean_form
  409.             cleaned_data = self.clean()

File "/antenv/lib/python3.7/site-packages/django/contrib/auth/forms.py" in clean
  196.             self.user_cache = authenticate(self.request, username=username, password=password)

File "/antenv/lib/python3.7/site-packages/django/contrib/auth/__init__.py" in authenticate
  73.             user = backend.authenticate(request, **credentials)

File "/antenv/lib/python3.7/site-packages/django/contrib/auth/backends.py" in authenticate
  16.             user = UserModel._default_manager.get_by_natural_key(username)

File "/antenv/lib/python3.7/site-packages/django/contrib/auth/base_user.py" in get_by_natural_key
  44.         return self.get(**{self.model.USERNAME_FIELD: username})

File "/antenv/lib/python3.7/site-packages/django/db/models/manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/antenv/lib/python3.7/site-packages/django/db/models/query.py" in get
  393.         num = len(clone)

File "/antenv/lib/python3.7/site-packages/django/db/models/query.py" in __len__
  250.         self._fetch_all()

File "/antenv/lib/python3.7/site-packages/django/db/models/query.py" in _fetch_all
  1186.             self._result_cache = list(self._iterable_class(self))

File "/antenv/lib/python3.7/site-packages/django/db/models/query.py" in __iter__
  54.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "/antenv/lib/python3.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1065.             cursor.execute(sql, params)

File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
  100.             return super().execute(sql, params)

File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
  68.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
  77.         return executor(sql, params, many, context)

File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "/antenv/lib/python3.7/site-packages/django/db/utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) from exc_value

File "/antenv/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /admin/login/
Exception Value: relation "auth_user" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
                                                             ^

Upvotes: 1

Views: 816

Answers (2)

neeraj9194
neeraj9194

Reputation: 373

If it's not asking for username then it might be your shell is not allowing it. You can use --noinput for that

python manage.py createsuperuser --noinput --username testuser --email [email protected]

You cannot set the password though, it will be set automatically you'd have to change it from admin panel.

Upvotes: 0

sandeshdaundkar
sandeshdaundkar

Reputation: 903

python manage.py makemigrations
python manage.py migrate

You might have forgotten to do makemigrations.

Upvotes: 1

Related Questions