gpt4 book ai didi

python - Django:当我尝试从管理员创建用户时出现操作错误

转载 作者:行者123 更新时间:2023-11-30 22:08:30 25 4
gpt4 key购买 nike

我有带 MySQL 的 Django 1.10,每次我进入管理员并尝试创建一个用户时,我都会收到此错误:

enter image description here

问题是我可以创建任何其他模型,如果我从命令行创建 super 用户我可以编辑该用户但是当我按“添加用户”时我得到这个错误。我尝试删除数据库并重新创建两次。

这是我的 settings.py:

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = [
# django apps
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

# our apps
'authentication',
'homepages',
'school'
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'config.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR + '/templates/'
],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'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 = 'config.wsgi.application'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'isj',
'USER': 'test_user',
'PASSWORD': 'password',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}

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',
},
]

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join('static'), )

最佳答案

在我的案例中,我发现根本原因是 MySQL-Python 数据库驱动程序,解决方法是使用其他适用于 Python 的 MySQL 驱动程序(例如 mysqlclient).

$ pip uninstall MySQL-Python
$ pip install mysqlclient

MySQL-python 结果很旧(最后一次提交是 7 年前)。 mysqlclient 是它的现代版本,有很多改进和错误修复。

有关我的修复和发现的更多详细信息 here .

关于python - Django:当我尝试从管理员创建用户时出现操作错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40905738/

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