我是django的新手,将不胜感激。
我已经安装了django-excel教程应用程序,并对其model.py文件进行了更改。
我已完成以下步骤:
1)python manage.py makemigrations民意调查
输出:“民意调查”的迁移: 民意调查\ migrations \ 0001_initial.py -创建模型hpcl
2)python manage.py迁移民意调查
输出:要执行的操作: 应用所有迁移:民意调查 运行迁移: 没有要申请的迁移。
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
答案 0 :(得分:0)
我按照答案中提到的步骤解决了上述问题: (查看详细说明) Django - no such table exception
您需要按照以下简单步骤来解决上述问题:
1)删除项目目录中的数据库(在我的情况下为db.sqlite3)
2)从项目子目录下的 pycache 文件夹中删除所有内容
3)对于您要修复的应用程序,转到文件夹并清除迁移和 pycache 目录
确定已清除所有上述文件后,运行:
python manage.py makemigrations
python manage.py migration