0

我正在开发一个 django 项目(网站),我在 2 个月前开始编码,在使用 django 项目时我遇到了一个问题。

实际上,我正在学习如何制作网站,当我登录到管理员时它工作正常但是当我添加产品时它会显示

[OperationalError at /admin/products/product/add/
no such table: main.auth_user__old
Request Method: POST
Request URL:    http://127.0.0.1:8000/admin/products/product/add/
Django Version: 3.0.6
Exception Type: OperationalError
Exception Value:    
no such table: main.auth_user__old
Exception Location: C:\Users\Owner\PycharmProjects\Pyshop\venv\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 396
Python Executable:  C:\Users\Owner\PycharmProjects\Pyshop\venv\Scripts\python.exe
Python Version: 3.8.2
Python Path:    
['C:\\Users\\Owner\\PycharmProjects\\Pyshop',
 'C:\\Users\\Owner\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
 'C:\\Users\\Owner\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
 'C:\\Users\\Owner\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
 'C:\\Users\\Owner\\AppData\\Local\\Programs\\Python\\Python38-32',
 'C:\\Users\\Owner\\PycharmProjects\\Pyshop\\venv',
 'C:\\Users\\Owner\\PycharmProjects\\Pyshop\\venv\\lib\\site-packages']
Server time:    Wed, 27 May 2020 04:31:07 +0000][1]

请在这件事上给予我帮助

这是那些文件

模型.py:

from django.db import models


class Product(models.Model):
name = models.CharField(max_length=255)
price = models.FloatField()
stock = models.IntegerField()
image_url = models.CharField(max_length=2083)


class Offer(models.Model):
code = models.CharField(max_length=10)
description = models.CharField(max_length=255)
discount = models.FloatField(5)

视图.py:

from django.http import HttpResponse
from django.shortcuts import render


def index(request):
return HttpResponse('Hello world')


def new(request):
return HttpResponse('New Products!!!!!!!!!!!!!')


def microsoft(request):
return HttpResponse('microsoft 365')

项目 urls.py:

"""pyshop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import:  from my_app import views
2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
1. Add an import:  from other_app.views import Home
2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('product/', include('product.urls'))
]

产品.url.py:

from django.urls import path
from . import views


urlpatterns = [
path('', views.index),
path('new/', views.new),
path('microsoft/', views.microsoft)
]

这是那些视图,模型。urls文件请解决问题!!!!

4

1 回答 1

0

首先检查你是否有同步你的数据库,即通过运行

python manage.py makemigrations
python manage.py migrate

如果这显示一些错误或不起作用,请尝试删除所有迁移文件,然后再次运行__pychache__makemigrations__init__.py和迁移命令。

于 2020-05-27T05:22:39.913 回答