python - 坚持我在 Udemy 上做的 Django 项目教程 - OperationalError at /admin/jobs/job/add/ 没有这样的表:main.auth_user__old
问题描述
我正在做一个从 Udemy 买来的 Django 教程。它的标题是“Django 2.2 & Python | The Ultimate Web Development Bootcamp”,以防你们中的一些人知道讲师 Nick 的本教程(有些东西,忘记姓氏了)。我正在使用 Django 2.0.2,这正是教程中所要求的。SQLite3 数据库版本 3.27.2,使用最新版本的 Spyder 和 Anaconda 提示符,我在 Windows 10 Pro 上,最新版本的“virtualenv”和“pip”也是如此。所以在教程中,我必须登录管理页面并创建一个名为“jobs”的应用程序,其中包含一个名为“Job”的 jobs.models.py 类。它将它添加到管理 UI,然后单击它并添加(使用右上角的“+”图标)一个“作业”,它正在添加一个 ImageField 和一个被添加的 CharField。单击“保存”时,我在 django 管理页面上收到错误消息。我的项目名称是“portfolio-project”,子文件夹包括“portfolio”、“blog”和“jobs”。
我回过头来重新做了教程中的所有步骤,并“按部就班”地做到了。我已经针对该错误研究了许多问题,但找不到任何有效的方法。我尝试了makemigrations,然后迁移。这可能是最新的 Django 和 SQLite 的错误,但不确定。
./portfolio-project/jobs/models.py '''
from django.db import models
# Create your models here.
class Job(models.Model):
image = models.ImageField(upload_to='images/')
summary = models.CharField(max_length=200)
'''
./portfolio-project/jobs/admin.py '''
from django.contrib import admin
from .models import Job
admin.site.register(Job)
'''
./portfolio-project/portfolio/settings.py ''' """
Django settings for portfolio project.
Generated by 'django-admin startproject' using Django 2.0.2.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'qe=d*&syck0@rb6y6lo2f$+*mp=9p4m5zr6o^10+wb-%ti$w!g'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'jobs.apps.JobsConfig',
'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 = 'portfolio.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 = 'portfolio.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.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/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
# added this for the project...not here by default
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# added this for the project...not here by default
MEDIA_URL = '/media/'
'''
我希望管理页面说我“保存”了“作业”,但我收到了这个错误:'''
OperationalError at /admin/jobs/job/add/
no such table: main.auth_user__old
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/jobs/job/add/
Django Version: 2.0.2
Exception Type: OperationalError
Exception Value:
no such table: main.auth_user__old
Exception Location: C:\Users\John\myenv\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 303
Python Executable: C:\Users\John\myenv\Scripts\python.exe
Python Version: 3.7.3
Python Path:
['C:\\Users\\John\\portfolio-project',
'C:\\Users\\John\\myenv\\Scripts\\python37.zip',
'C:\\Users\\John\\myenv\\DLLs',
'C:\\Users\\John\\myenv\\lib',
'C:\\Users\\John\\myenv\\Scripts',
'C:\\Users\\John\\Anaconda3\\Lib',
'C:\\Users\\John\\Anaconda3\\DLLs',
'C:\\Users\\John\\myenv',
'C:\\Users\\John\\myenv\\lib\\site-packages']
Server time: Fri, 6 Sep 2019 19:13:44 +0000
'''
解决方案
尝试这个
git add -A
git commit -m
python manage.py makemigrations
python manage.py migrate
推荐阅读
- javascript - 为来自特定站点的访问者显示特定内容
- html - 我应该总是在
- html - 将 facebook 图标向左移动
- postgresql - 如何在 Postgresql 中插入数据而不必指明主键列?
- angular - 传单:如何只显示一个地图实例?
- html - 为什么 request.GET.get 不捕获这个参数?
- r - R Keras 错误:py_call_impl 中的错误(可调用,dots$args,dots$keywords):ValueError:未提供数据
- django - 在 Ajax 中显示 ValidationError
- javascript - 如何更改 Axios 响应中的变量值?
- r - 将操作数据Stata转换为R:if和递归值在同一行