卡在我正在 Udemy 上做的 Django 项目教程 - 操作错误在 /admin/jobs/job/add/ 没有这



我正在做一个从Udemy买来的Django教程。它的标题是"Django 2.2 & Python |终极Web开发训练营",以防你们中的一些人知道讲师Nick的本教程(有些东西,忘记了姓氏(。我正在使用 Django 2.0.2,这正是教程中提出的。SQLite3数据库版本3.27.2,使用最新版本的Spyder和Anaconda提示符,我使用的是Windows 10 Pro,最新版本的"virtualenv"和"pip"。 因此,在本教程中,我必须登录管理页面并创建一个名为"jobs"的应用程序,其中包含一个名为"Job"的 jobs.models.py 类。它将其添加到管理 UI 中,然后单击它并添加(使用右上角的"+"图标(一个"作业",这将添加一个图像字段和一个添加的字符字段。当我单击"保存"时,我在 django 管理页面上收到错误。我的项目名称是"投资组合项目",子文件夹包括"投资组合","博客"和"工作"。

我回过头来重新做了教程中到那时为止的所有步骤,并"不折不扣"地完成了。我已经针对该错误研究了许多问题,但找不到任何有效的方法。我尝试了迁移,然后迁移。这可能是最新的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:UsersJohnmyenvlibsite-packagesdjangodbbackendssqlite3base.py in execute, line 303
Python Executable:  C:UsersJohnmyenvScriptspython.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

'''

在 Django 2.0.2 如何与 Sqlite3 一起工作之前,我遇到了这样的问题,最好的解决方法是将 Django 更新到最新版本,或使用 postgresql 数据库。

试试这个

git add -A git commit -m python manage.py makemigrations python manage.py migrate

最新更新