gpt4 book ai didi

python - 如何在 ssh 中创建 Django super 用户?

转载 作者:行者123 更新时间:2023-12-03 02:39:47 26 4
gpt4 key购买 nike

我正在 Azure 中为学校项目部署 Django 和 PostgreSQL,按照此 tutorial 。我正在使用 Django 2.1.2 和 Python 3.7.5。

在本教程的“运行数据库迁移”步骤中,系统指示我打开 SSH session 并运行以下命令:

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

当我运行“createsuperuser”命令时,我希望提示输入用户名、电子邮件地址和密码,但系统不会提示我输入任何这些内容。相反,SSH session 会提示我输入另一个输入,如下所示:

enter image description here

因此,我无法登录我的 Django 安装。当我尝试登录时,我收到以下错误消息:

ProgrammingError at /admin/login/

回溯位于此消息的末尾。

我希望能够在 Django 中创建一个 super 用户,并使用该 super 用户帐户来配置应用程序。相反,我收到了编程错误消息并且无法继续。

如有任何帮助,我们将不胜感激。我在 Google 上搜索了各种错误消息,搜索了 StackOverflow,并在 YouTube 上搜索了教程,但我遇到了障碍。

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...
^

最佳答案

python manage.py makemigrations
python manage.py migrate

您可能忘记进行 makemigrations。

关于python - 如何在 ssh 中创建 Django super 用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61707288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com