Trying to create a super user for my database:
manage.py createsuperuser
Getting a sad recursive message:
Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser
in your project to create one manually.
Seriously Django? Seriously?
The only information I found for this was the one listed above but it didn’t work:
Unable to create superuser in django due to not working in TTY
And this other one here, which is basically the same:
Can’t Create Super User Django
asked Sep 11, 2015 at 22:15
6
If you run
$ python manage.py createsuperuser
Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser
in your project to create one manually.
from Git Bash and face the above error message try to append winpty
i.e. for example:
$ winpty python manage.py createsuperuser Username (leave blank to use '...'):
To be able to run python
commands as usual on windows as well what I normally do is appending an alias line to the ~/.profile
file i.e.
MINGW64 ~$ cat ~/.profile
alias python='winpty python'
After doing so, either source the ~/.profile
file or simply restart the terminal and the initial command python manage.py createsuperuser
should work as expected!
answered May 7, 2016 at 20:55
Evgeny BobkinEvgeny Bobkin
4,0622 gold badges17 silver badges21 bronze badges
3
In virtualenv, for creating super-user for Django project related to git-bash use the command:
winpty python manage.py createsuperuser.
jcaliz
3,8712 gold badges8 silver badges13 bronze badges
answered Apr 13, 2020 at 3:12
1
I had same problem when trying to create superuser in the docker container with command:
sudo docker exec -i <container_name> sh
. Adding option -t solved the problem:
sudo docker exec -it <container_name> sh
answered Apr 13, 2019 at 12:29
markemarke
1,0247 silver badges20 bronze badges
Since Django 3.0 you can create a superuser without TTY in two ways
Way 1: Pass values and secrets as ENV in the command line
DJANGO_SUPERUSER_USERNAME=admin2 DJANGO_SUPERUSER_PASSWORD=psw
python manage.py createsuperuser --email=admin@admin.com --noinput
Way 2: set DJANGO_SUPERUSER_PASSWORD as the environment variable
# .admin.env
DJANGO_SUPERUSER_PASSWORD=psw
# bash
source '.admin.env' && python manage.py createsuperuser --username=admin --email=admin@admin.com --noinput
The output should say: Superuser created successfully.
answered Jan 5, 2022 at 13:09
pymenpymen
5,53743 silver badges35 bronze badges
To create an admin username and password, you must first use the command:
python manage.py migrate
Then after use the command:
python manage.py createsuperuser
Once these steps are complete, the program will ask you to enter:
- username
- password
With the password, it will not show as you are typing so it will appear as though you are not typing, but ignore it as it will ask you to renter the password.
When you complete these steps, use the command:
python manage.py runserver
In the browser add «/admin», which will take you to the admin site, and then type in your new username and password.
answered Nov 15, 2019 at 18:02
darrelldarrell
531 silver badge4 bronze badges
Check your docker-compose.yml file and make sure your django application is labeled by web under services.
answered Nov 12, 2021 at 8:04
EILYAEILYA
3374 silver badges5 bronze badges
I tried creating superuser from Stash [ App: Pythonista on iOS ]
[ Make sure migrations are already made ]
$ django-admin createsuperuser
answered Nov 20, 2020 at 5:12
I figured out how to do so. What I did was I went to VIEWS.py. Next, I imported the module os
. Then I created a function called createSuperUser(request):
. Then, I then created a variable called admin
and set it equal to os.system("python manage.py createsuperuser")
. Then after that, return admin
. Finally, I restarted the Django site, then it will prompt you in the terminal.
import os
def createSuperUser(request):
admin = os.system("python manage.py createsuperuser")
return
Gino Mempin
24.5k28 gold badges92 silver badges128 bronze badges
answered Nov 20, 2019 at 22:38
darrelldarrell
531 silver badge4 bronze badges
I am trying to create a superuser through createsuperuser command in manage.py console is throwing an error «No Django settings specified. Also tried in python console by runninf python manage.py createsuperuser
Unknown command: ‘createsuperuser’
Type ‘manage.py help’ for usage.»
I AM USING PYCHARM
settings.py
"""
Django settings for MovieFlix project.
Generated by 'django-admin startproject' using Django 4.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-#*8cdy*ul906(s4ei#g7h17)vv%)#0s5b##weupzn-&ct@ylez'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['192.168.2.12', '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Core.apps.CoreConfig',
'movie.apps.MovieConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',
]
ROOT_URLCONF = 'MovieFlix.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'Core/templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'MovieFlix.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
# 'default': {
# 'ENGINE': 'djongo',
# 'NAME': 'MovieFlix',
# 'ENFORCE_SCHEMA': False,
# 'CLIENT': {
# 'host': 'mongodb+srv://movieflix:movieflix%401234@cluster0.fm15x.mongodb.net/MovieFlix?retryWrites=true&w=majority'
# }
# }
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
manage.py
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MovieFlix.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
Django
February 18, 2021
1 Minute
Error
When I tried to run this command: python manage.py createsuperuser
in my Django project, it gave me a super long error which included the following:
File “manage.py”, line 22, in
main()
File “manage.py”, line 18, in main
execute_from_command_line(sys.argv)
File “/Users/username/.local/share/virtualenvs/django-learn-csZU2bYZ/lib/python3.8/site-packages/django/core/management/init.py”, line 364, in execute_from_command_line
utility.execute()
….
ImportError: cannot import name ‘path’ from ‘django.urls’ (/Users/username/.local/share/virtualenvs/django-learn-csZU2bYZ/lib/python3.8/site-packages/django/urls/init.py)
Solution
The problem in my case was that I had the wrong version of Django installed. In order to run the python manage.py createsuperuser
command you need at least Django 2.
Run this command to check the version of Django you are currently working with:
python -m django --version
Run this command to install the latest version of Django.
pip install --upgrade django
Run the python -m django --version
command again and make sure your new Django version is 2.x or above. If so, you should be able to run python manage.py createsuperuser
now
Published
February 18, 2021
Вобщем-то вот.
(env) fix@catiger:~/app$ python manage.py createsuperuser
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 "/home/fix/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/fix/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/fix/env/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/fix/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/home/fix/env/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/fix/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 111, in handle
username = self.get_input_data(self.username_field, message, default_username)
File "/home/fix/env/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 209, in get_input_data
raw_value = input(message)
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-2: ordinal not in range(256)
Кусок settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',
]
ROOT_URLCONF = 'app.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'app.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
Уже строго(!!!) по мануалу делаю. Четвёртый день.
Сначала без venv пробовал глобально всё поставить, там хоть страницу джанго увидел, но статика не работала. Снёс всё вместе с убунту и так много раз.
Теперь вот третья попытка с venv и всё время на этом месте такая петрушка.
Миграции прошли успешно.
Ах, да вот локаль.
root@catiger:~# locale -a | grep UTF-8
C.UTF-8
#19067
closed
Bug
(fixed)
Reported by: | Owned by: | Ian Clelland | |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | django@…, tom@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
There is a dependency in the createsuperuser management command on the existence of a field called ‘username’ in a user model.
Since #3011 was fixed, user models do not necessarily have that field. They are required to have a single identifying field, which is passed in as the first parameter to their create_superuser() method, but it is not necessarily named username
.
As a result, if syncdb installs django.contrib.auth, and the user model does not have a ‘username’ field, then the creation of the initial superuser will fail.
I have a (one line) patch which fixes this, and will try to get tests written for it later today.
Change History (14)
Has patch: | set |
---|---|
Needs tests: | set |
Owner: | changed from nobody to Ian Clelland |
Component: |
contrib.auth → Documentation |
---|---|
Needs documentation: | set |
Needs tests: | unset |
Patch needs improvement: | set |
Triage Stage: |
Unreviewed → Accepted |
Resolution: | → needsinfo |
---|---|
Status: |
new → closed |
Resolution: | needsinfo |
---|---|
Status: |
closed → reopened |
Needs documentation: | unset |
---|---|
Patch needs improvement: | unset |
Resolution: | → fixed |
---|---|
Status: |
reopened → closed |
Note: See
TracTickets for help on using
tickets.