如何解决django中的管理操作问题?

c9x0cxw0  于 2023-03-04  发布在  Go
关注(0)|答案(2)|浏览(140)

我正在做一个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]

请帮我一下
这些文件在这里
models.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)

views.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'))
]

product.url.py:

from django.urls import path
from . import views

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

这里是那些意见,模型. urls文件请解决这个问题!!!

4dbbbstv

4dbbbstv1#

首先检查是否已同步数据库,即运行

python manage.py makemigrations
python manage.py migrate

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

plicqrtu

plicqrtu2#

您所要做的就是在www.example.com步骤中创建模型后进行迁移models.py:
1.在www.example.com中创建模型models.py
1.转到cmd并转到项目的路径(运行服务器的位置)
3)键入命令:pythonmanage.py迁移
4)单击回车
4)然后键入:pythonmanage.py进行迁移
5)在放置应用程序的名称之后单击回车
6)键入命令:pythonmanage.py迁移
就这样问题就解决了

相关问题