0

i am working on an django project (website) i started coding 2 months ago and while working with django project i stucked at a problem.

Actually, I am learning how to make websites, And when i login to admin it works fine but when i add product then it shows

[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]

Please help me with this

here are those files

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')

project 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)
]

here are those views, models. urls files please solve the problem !!!!

Piyush Jangid
  • 17
  • 1
  • 3

2 Answers2

0

First check if you have syn your database i.e. by running

python manage.py makemigrations
python manage.py migrate

If this shows some error or doesn't work then try deleting all migration files and __pychache__ except __init__.py and run makemigrations and migrate commands again.

Sheraram_Prajapat
  • 589
  • 1
  • 9
  • 27
  • i removed all migration files and catch files and run those commands and again the same problem was showing – Piyush Jangid May 28 '20 at 05:39
  • Thank You, bhaiya for your concern, i am starting my project from scratch if i face problem then please solve that thank you again @Sheraram Prajapat, Pruthvi Barot – Piyush Jangid May 30 '20 at 04:46
  • hello i've faced the same problem again after restarting the problem please help me!!! this operational error admin/product/add @Sheraram_Prajapat – Piyush Jangid Jun 02 '20 at 08:33
  • 1
    please add your models, views and urls so we may look at where/what is causing problem/error. – Sheraram_Prajapat Jun 02 '20 at 14:31
  • i've posted the files mentioned above in the question only please refer that and help me please!!!!!! And yes i am programming in windows but the tutorial from which i am learning is mac now please help me!!!!! @Sheraram_Prajapat – Piyush Jangid Jun 03 '20 at 05:00
  • @PiyushJangid Please stop pinging others several time. They are notified the first time and will decide when and if they have time to help. Also, please avoid using the desperate tone and many exclamation marks. It comes across as pretty rude because it can be seen as putting others under pressure - remember, we are all volunteers here with limited time. – Modus Tollens Jun 04 '20 at 04:30
  • 1
    Ok sir, sorry for that i don't know next time i will remember@ModusTollens – Piyush Jangid Jun 04 '20 at 04:40
  • hi please help me with this my project is stucked at this please help me.@Sheraram_Prajapat – Piyush Jangid Jun 08 '20 at 04:00
  • @Piyush Jangid, I haven't encountered such error and whenever I do encounter related to database, I simply delete pychache and migration of apps as well as project and sqlite3 database too, make sure you have Django updated or you can downgrade your Django to version 2. For mare info look https://stackoverflow.com/questions/53637182/django-no-such-table-main-auth-user-old – Sheraram_Prajapat Jun 08 '20 at 05:24
  • how can i delete sqlite3 file, actually it is not deleting from pycharm IDE,can you tell me how to delete pychache and migration for above both. @Sheraram_Prajapat – Piyush Jangid Jun 08 '20 at 13:24
  • i've updated my django to version 3.0.7 but nothing is working?@Sheraram_Prajapat – Piyush Jangid Jun 08 '20 at 13:28
  • Then I would suggest please start a new project. sorry I can't help you – Sheraram_Prajapat Jun 08 '20 at 15:40
  • i've previously started the new project only actually i am creating my project in pycharm IDE and in that my sqlite3 file's icon on pycharm is question mark is showing and when i copy sqlite 3 file to db browser then it is showing that file is not a database it is related to database ? @Sheraram_Prajapat – Piyush Jangid Jun 09 '20 at 12:15
  • No idea I don't use pycharm. I use VS Code – Sheraram_Prajapat Jun 09 '20 at 12:33
0

all you have to do is to migrate after creating the models in models.py steps:

  1. create the models in models.py

  2. go to cmd and go to the path of your project ( the place where you run the server)

3)type the command :python manage.py migrate

4)click enter

4)then type : python manage.py makemigrations

5)in the place of put the name of your app after that click enter

6)type the command :python manage.py migrate

that's all and the problem is solved