I have a django project with hundreds of unit tests and after a big update that added about 50 more tests, all the project's tests that creates an instance of a specific model are failing with the following error message:
Traceback (most recent call last):
File ".../venv/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1142, in execute_sql
cursor.execute(sql, params)
File ".../venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File ".../venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File ".../venv/lib/python3.9/site-packages/django/db/backends/utils.py", line 79, in _execute
self.db.validate_no_broken_transaction()
File ".../venv/lib/python3.9/site-packages/django/db/backends/base/base.py", line 437, in validate_no_broken_transaction
raise TransactionManagementError(
django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
During handling of the above exception, another exception occurred:
File ".../venv/lib/python3.9/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File ".../venv/lib/python3.9/site-packages/django/db/models/query.py", line 653, in first
for obj in (self if self.ordered else self.order_by('pk'))[:1]:
File ".../venv/lib/python3.9/site-packages/django/db/models/query.py", line 274, in __iter__
self._fetch_all()
File ".../venv/lib/python3.9/site-packages/django/db/models/query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File ".../venv/lib/python3.9/site-packages/django/db/models/query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File ".../venv/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1145, in execute_sql
cursor.close()
File ".../venv/lib/python3.9/site-packages/MySQLdb/cursors.py", line 83, in close
while self.nextset():
File ".../venv/lib/python3.9/site-packages/MySQLdb/cursors.py", line 137, in nextset
nr = db.next_result()
MySQLdb._exceptions.OperationalError: (2006, '')
The update did not change any models at all and no migrations were made.
The tests seem to work if I change class SomeTest(TestCase) to class SomeTest(TransactionTestCase) in all tests, but then they get extremely slow and take several hours to run. (They usually took 2 minutes two run before this error.)
I'm using python 3.9, django 2.2.28, and mysql 8.0.23.
I tried upgrading to django 3.2 but that did not fix the problem.
I also tried not running all the new tests with --exclude-tag on the command line, but it would still raise the same errors.
Related
I am starting with Django and I got this problem. I understand only that there is a problem with database. I would really like to get some help. Thank you, If it is important I use Fedora 33
Guys really, not my bad that the 90% of problem is code, let me as a question XD
(project_venv) [mikolajwojtowicz#localhost src]$ python3 manage.py makemigrations
Traceback (most recent call last):
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute
return Database.Cursor.execute(self, query)
sqlite3.DatabaseError: file is not a database
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mikolajwojtowicz/Django/my_project/src/manage.py", line 22, in <module>
main()
File "/home/mikolajwojtowicz/Django/my_project/src/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/migrations/loader.py", line 290, in check_consistent_history
applied = recorder.applied_migrations()
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 56, in has_table
tables = self.connection.introspection.table_names(cursor)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
return get_names(cursor)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/base/introspection.py", line 43, in get_names
return sorted(ti.name for ti in self.get_table_list(cursor)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/introspection.py", line 74, in get_table_list
cursor.execute("""
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
File "/home/mikolajwojtowicz/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute
return Database.Cursor.execute(self, query)
django.db.utils.DatabaseError: file is not a database
The error log says:
sqlite3.DatabaseError: file is not a database
This means that your settings for the database are wrong. This setting is located in the settings.py in your core project's directory (this directory will also have wsgi.py and asgi.py)
Make sure your settings for db engine, name, user, and password are correct
Recently I migrated my local django + django-cms site to production server using following methods:
moved code to production server and populated db schema using makemigration and migrate commands
I exported the data using Pycharm's inbuilt database tool via "Dump data to File(s)" > "SQL-Insert-Statements.sql.groovy", the exported file had only insert statements and no other sql statement.
I copy pasted and executed these statements in query tool window using pgAdmin 4
I executed sql statements for reset sequences which I got from "python manage.py sqlsequencereset ..." command
Now after doing all this the website is working fine but on the admin side I can edit the page and it keeps the changes in database but throws error when I click on "publish page changes" button.
Here is the error:
django.db.utils.IntegrityError: duplicate key value violates unique constraint "cms_cmsplugin_path_4917bb44_uniq"
DETAIL: Key (path)=(0007) already exists.
Complete error stack:
[15/Jul/2020 21:13:40] "POST /en/admin/cms/page/45/en/publish/ HTTP/1.1" 500 25121
Internal Server Error: /en/admin/cms/page/45/en/publish/
Traceback (most recent call last):
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "cms_cmsplugin_path_4917bb44_uniq"
DETAIL: Key (path)=(0007) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/john/project1/env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/john/project1/env/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/john/project1/env/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/views/decorators/http.py", line 40, in inner
return func(request, *args, **kwargs)
File "/usr/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/admin/pageadmin.py", line 1125, in publish_page
all_published = page.publish(language)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/models/pagemodel.py", line 987, in publish
self._copy_contents(public_page, language)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/models/pagemodel.py", line 633, in _copy_contents
placeholder.copy_plugins(target_placeholder, language=language)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/models/placeholdermodel.py", line 580, in copy_plugins
root_plugin=root_plugin,
File "/home/john/project1/env/lib/python3.6/site-packages/cms/utils/plugins.py", line 214, in copy_plugins_to_placeholder
new_plugin = CMSPlugin.add_root(instance=new_plugin)
File "/home/john/project1/env/lib/python3.6/site-packages/treebeard/mp_tree.py", line 625, in add_root
return MP_AddRootHandler(cls, **kwargs).process()
File "/home/john/project1/env/lib/python3.6/site-packages/treebeard/mp_tree.py", line 345, in process
newobj.save()
File "/home/john/project1/env/lib/python3.6/site-packages/djangocms_text_ckeditor/models.py", line 64, in save
super(AbstractText, self).save(*args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/cms/models/pluginmodel.py", line 270, in save
super(CMSPlugin, self).save(*args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 741, in save
force_update=force_update, update_fields=update_fields)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 776, in save_base
parent_inserted = self._save_parents(cls, using, update_fields)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 807, in _save_parents
force_insert=parent_inserted,
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 870, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/base.py", line 908, in _do_insert
using=using, raw=raw)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1368, in execute_sql
cursor.execute(sql, params)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/john/project1/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "cms_cmsplugin_path_4917bb44_uniq"
DETAIL: Key (path)=(0007) already exists.
something similar happened to me after migrating from sqlite to postgresql and I thought it was a problem with this.
But searching I found that it was a Treebeard 4.5 problem.
And the solution that worked for me was to Rollback to version 4.4.
https://github.com/django-cms/django-cms/issues/6980
I am using Django shell for debug purpose of my project by using command python manage.py shell.
I have found that I am not able to execute ORM queries from shell & getting below kind of error.
from base.models import Template_Form, Template_Form_Field
Template_Form_Field.objects.all()
After executing above code in shell I am getting below error.
Traceback (most recent call last):
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "base_template_form_field" does not exist
LINE 1: ...ions", "base_template_form_field"."sequence" FROM "base_temp...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\models\query.py", line 250, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\models\query.py", line 274, in __iter__
self._fetch_all()
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\models\query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\models\query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1100, in execute_sql
cursor.execute(sql, params)
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "D:\production\siralo\siralo_py3\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "base_template_form_field" does not exist
LINE 1: ...ions", "base_template_form_field"."sequence" FROM "base_temp...
Does anybody have idea why am I getting above error & how to get rid of it.
I have tried to search on google but not able to find any solution.
Template form field model is as below.
class Template_Form_Field(models.Model):
template_form = models.ForeignKey(Template_Form, on_delete=models.CASCADE)
name = models.CharField(max_length=40, verbose_name='Name')
caption = models.CharField(max_length=80, verbose_name='Caption')
value_options = models.TextField(null=True, blank=True, verbose_name='Value options')
sequence = models.IntegerField(blank=True, null=True, verbose_name='Sequence')
Thanks.
just run python manage.py migrate
this error is because you have just run python manage.py makemigrations but did'nt run python manage.py migrate.
i also encounter the same error in shell while i have not run the migrate command below is the screen shot of error i get this is the screenshot of the same error
Present states
I made easy "to do list". I copied and pasted from Japanese website.
These procedures was going well on the way, however when I set up local server, this error occurred
python manage.py runserver 8080
Performing system checks...
System check identified no issues (0 silenced).
You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
October 14, 2019 - 18:23:49
Django version 2.2.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8080/
Quit the server with CTRL-BREAK.
C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\list.py:88: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'todo.models.Todo'> QuerySet.
allow_empty_first_page=allow_empty_first_page, **kwargs)
Internal Server Error: /todo/list/
Traceback (most recent call last):
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: todo_todo
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\list.py", line 157, in get
context = self.get_context_data()
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\list.py", line 119, in get_context_data
paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\views\generic\list.py", line 69, in paginate_queryset
page = paginator.page(page_number)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\paginator.py", line 70, in page
number = self.validate_number(number)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\paginator.py", line 48, in validate_number
if number > self.num_pages:
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\paginator.py", line 97, in num_pages
if self.count == 0 and not self.allow_empty_first_page:
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\core\paginator.py", line 91, in count
return c()
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\models\query.py", line 392, in count
return self.query.get_count(using=self.db)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\models\sql\query.py", line 504, in get_count
number = obj.get_aggregation(using, ['__count'])['__count']
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\models\sql\query.py", line 489, in get_aggregation
result = compiler.execute_sql(SINGLE)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1100, in execute_sql
cursor.execute(sql, params)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\kazu\Anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: todo_todo
[14/Oct/2019 18:25:18] "GET /todo/list/ HTTP/1.1" 500 165625
Not Found: /favicon.ico
[14/Oct/2019 18:25:19] "GET /favicon.ico HTTP/1.1" 404 2077
I don't spot the file which have the errors. so If you know what file has the errors, could you pls tell me? I will post the code in the file.
sqlite3.OperationalError: no such table: todo_todo,
This means you have no table called todo in your database - db.sqlite3. You need to make migrations which is standard step in django when do changes in model and then create tables in your db via commands mentioned above in comments by #YevhenKuzmovych.
python manage.py makemigrations
then
python manage.py migrate
Make it a habit to always run these two commands when you do any changes to your models.py which contain your model classes
I am unable to run makemigrations, migrate, or anything else (flush, reset_db from django-extensions) if I have a certain app in my INSTALLED_APPS.
The app is called issues and has one model:
class Issue(models.Model):
title = models.CharField(max_length=255)
description = models.CharField(max_length=1000)
sent = models.BooleanField()
And it was working before (makemigrations and migrate ran fine and I could use the app/model correctly), until I tried adding:
severity = models.IntegerField()
and tried to run makemigrations. I don't have the error or remember it anymore, but since then everything is broken, even after removing severity from the model.
Everything works if I remove the issues app from my settings.py.
The error I get:
madjura#madjura-E6228:~/workspace/budget/src$ python3.5 manage.py makemigrationsTraceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: issues_issue
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/madjura/workspace/budget/src/issues/apps.py", line 16, in ready
issues.models.Issue.objects.check_and_send_unsent_issues()
File "/home/madjura/workspace/budget/src/issues/models.py", line 18, in check_and_send_unsent_issues
for issue in issues:
File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 256, in __iter__
self._fetch_all()
File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 1087, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql()
File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python3.5/dist-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: issues_issue
While issues is in INSTALLED_APPS I get the same error when running migrate, flush and reset_db.
I have tried running flush and reset_db with issues removed from INSTALLED_APPS, this did not solve the problem.
I have tried doing the above and then running makemigrations and migrate, this does also not work. As soon as I put issues back in INSTALLED_APPS everything is broken.
How can I fix this?
EDIT:
Maybe relevant, the issue model has a Manager with a function:
class IssueManager(models.Manager):
"""Manager for the Issue class."""
def check_and_send_unsent_issues(self):
"""
Checks for unsent Issue objects (Issue.sent = False) and attempts
to send them.
Issues that have been sent are deleted.
If the issue fails to be sent for whatever reason, it is not deleted.
Does nothing if there are no unsent issues.
This method is called once when the server starts.
"""
issues = self.get_queryset().filter(sent=False)
for issue in issues:
try:
make_issue(issue.title, issue.description)
issue.delete()
except PostIssueException:
pass
Using apps.py I check for unsent issues and post them on Gitlab.
EDIT 2:
Issue resolved by commenting the line below which appears in my apps.py, in ready():
issues.models.Issue.objects.check_and_send_unsent_issues()
Which somehow caused things to break, I don't understand why. Could someone explain that please?
Try moving the line import issues.models into def ready() to prevent loading the models too early.