0

I'm getting the following error when I make changes in the admin page: OperationalError at /admin/products/product/add/

In the admin page there is and product column, where I can add new products. I am able to access the admin page but after adding product's name, price, stock, image, whenever I click on save button it is giving me this error.

Please make any suggestions on this, I am new in django. I am adding the codes:

models.py

from django.db import models
from django.db.models.fields import CharField 


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

admin.py

from django.contrib import admin
from .models import Product

admin.site.register(Product)

I have done migrations several times but it is still showing this error.:-(

this is the full error message

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: 2.1
Exception Type: OperationalError
Exception Value:    
no such table: main.auth_user__old
Exception Location: C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 296
Python Executable:  C:\Users\LENOVO\anaconda3\python.exe
Python Version: 3.8.5
Python Path:    
['C:\\Users\\LENOVO\\Desktop\\Python\\pyshop',
 'C:\\Users\\LENOVO\\anaconda3\\python38.zip',
 'C:\\Users\\LENOVO\\anaconda3\\DLLs',
 'C:\\Users\\LENOVO\\anaconda3\\lib',
 'C:\\Users\\LENOVO\\anaconda3',
 'C:\\Users\\LENOVO\\anaconda3\\lib\\site-packages',
 'C:\\Users\\LENOVO\\anaconda3\\lib\\site-packages\\win32',
 'C:\\Users\\LENOVO\\anaconda3\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\LENOVO\\anaconda3\\lib\\site-packages\\Pythonwin']
Server time:    Fri, 4 Dec 2020 17:45:07 +0000

this is the traceback message

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/products/product/add/

Django Version: 2.1
Python Version: 3.8.5 
    Installed Applications:
    ['django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'products.apps.ProductsConfig']
    
    Installed 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']

Traceback:

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  296.         return Database.Cursor.execute(self, query, params)

The above exception (no such table: main.auth_user__old) was the direct cause of the following exception:

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\core\handlers\base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\core\handlers\base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\contrib\admin\options.py" in wrapper
  607.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\contrib\admin\sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\contrib\admin\options.py" in add_view
  1647.         return self.changeform_view(request, None, form_url, extra_context)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\utils\decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\contrib\admin\options.py" in changeform_view
  1536.             return self._changeform_view(request, object_id, form_url, extra_context)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\contrib\admin\options.py" in _changeform_view
  1579.                     self.log_addition(request, new_object, change_message)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\contrib\admin\options.py" in log_addition
  807.         return LogEntry.objects.log_action(

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\contrib\admin\models.py" in log_action
  29.         return self.model.objects.create(

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\query.py" in create
  413.         obj.save(force_insert=True, using=self.db)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\base.py" in save
  716.         self.save_base(using=using, force_insert=force_insert,

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\base.py" in save_base
  747.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\base.py" in _save_table
  830.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\base.py" in _do_insert
  867.         return manager._insert([self], fields=fields, return_id=update_pk,

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\query.py" in _insert
  1133.         return query.get_compiler(using=using).execute_sql(return_id)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  1285.                 cursor.execute(sql, params)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\utils.py" in execute
  100.             return super().execute(sql, params)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\utils.py" in execute
  68.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\utils.py" in _execute_with_wrappers
  77.         return executor(sql, params, many, context)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) from exc_value

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "C:\Users\LENOVO\anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  296.         return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/products/product/add/
Exception Value: no such table: main.auth_user__old
thlik
  • 401
  • 6
  • 12

0 Answers0