gpt4 book ai didi

python - 用户注册错误 : no such table: auth_user

转载 作者:IT老高 更新时间:2023-10-28 22:12:52 25 4
gpt4 key购买 nike

我正在尝试使用 Django 的默认身份验证来处理注册和登录。

setting.py:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'books',
)

MIDDLEWARE_CLASSES = (
'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',
)

AUTH_USER_MODEL = 'books.User'

books.models.py:

class User(AbstractUser):
account_balance = models.DecimalField(max_digits=5, decimal_places=2, default=0)

views.py:

from django.contrib.auth.forms import UserCreationForm

def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect("/accounts/profile/")
else:
form = UserCreationForm()
return render(request, "registration/register.html", {'form': form,})

urls.py:

urlpatterns = patterns('',
(r'^accounts/login/$', login),
(r'^accounts/logout/$', logout),
(r'^accounts/profile/$', profile),
(r'^accounts/register/$', register),
)

我尝试删除 db.sqlite3 文件并重新运行 python manage.py syncdb 但我仍然收到此错误消息:

OperationalError at /accounts/register/
no such table: auth_user
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/register/
Django Version: 1.7b4
Exception Type: OperationalError
Exception Value:
no such table: auth_user

最佳答案

./manage.py migrate

如果您刚刚启用了所有中间件等,这将运行每个迁移并添加缺少的表。

关于python - 用户注册错误 : no such table: auth_user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24682155/

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