-1

I am new to django any help would be much appreciated.

I have installed the django-excel tutorial app and made changes to its model.py file.

I have done the following steps :

1) python manage.py makemigrations polls

Output : Migrations for 'polls': polls\migrations\0001_initial.py - Create model hpcl

2) python manage.py migrate polls

output : Operations to perform: Apply all migrations: polls Running migrations: No migrations to apply.

Model.py file 

from django.db import models


    class hpcl(models.Model):
        plannedPLT = models.IntegerField(default=0)
        pub_date = models.DateTimeField('date published')
        consumption = models.IntegerField(default=0)
        required_PLT = models.CharField(max_length=200)


        def __str__(self):
            return self.pub_date


Request Method: POST
Request URL: http://127.0.0.1:8000/polls/import/

Django Version: 2.2.1
Python Version: 3.7.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'polls')
Installed Middleware:
('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\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  383.         return Database.Cursor.execute(self, query, params)

The above exception (no such table: polls_hpcl) was the direct cause of the following exception:

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\dhaval1.desai\Documents\Notes\Feedstock\Django-excelV2\django-excel-master\polls\views.py" in import_data
  53.                     ['plannedPLT', 'pub_date', 'consumption', 'required_PLT']

File "C:\Users\dhaval1.desai\Documents\Notes\Feedstock\Django-excelV2\django-excel-master\django_excel\__init__.py" in save_book_to_database
  63.         pe.save_book_as(**params)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel\core.py" in save_book_as
  112.     return sources.save_book(book, **dest_keywords)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel\internal\core.py" in save_book
  56.     return _save_any(a_source, book)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel\internal\core.py" in _save_any
  60.     a_source.write_data(instance)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel\plugins\sources\db_sources.py" in write_data
  111.             **self._keywords

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel\plugins\renderers\django.py" in render_book_to_stream
  75.             **keywords

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel_io\io.py" in save_data
  129.         **keywords

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel_io\io.py" in store_data
  146.         writer.write(data)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel_io\book.py" in write
  221.                 sheet_writer.close()

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\pyexcel_io\database\importers\django.py" in close
  58.                 an_object.save()

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py" in save
  741.                        force_update=force_update, update_fields=update_fields)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py" in save_base
  779.                 force_update, using, update_fields,

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py" in _save_table
  870.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\base.py" in _do_insert
  908.                                using=using, raw=raw)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py" in _insert
  1186.         return query.get_compiler(using=using).execute_sql(return_id)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  1335.                 cursor.execute(sql, params)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in execute
  99.             return super().execute(sql, params)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in execute
  67.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in _execute_with_wrappers
  76.         return executor(sql, params, many, context)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) from exc_value

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

File "C:\Users\dhaval1.desai\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  383.         return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /polls/import/
Exception Value: no such table: polls_hpcl
Dharight
  • 71
  • 1
  • 8

1 Answers1

0

I solved the above problem by following the steps mentioned in the answer : (view for a detailed explanation) Django - no such table exception

You need to follow the following simple steps to resolve the above issue :

1)Delete your database (db.sqlite3 in my case) in your project directory

2)Remove everything from pycache folder under your project subdirectory

3)For the application you are trying to fix, go to the folder and clear migrations and pycache directories

When you are sure you have cleared all the above files, run:

python manage.py makemigrations

python manage.py migrate

Dharight
  • 71
  • 1
  • 8