jonaswinkler / paperless-ng

A supercharged version of paperless: scan, index and archive all your physical documents
https://paperless-ng.readthedocs.io/en/latest/
GNU General Public License v3.0
5.37k stars 355 forks source link

no such column: documents_tag.slug #341

Closed alex-phillips closed 3 years ago

alex-phillips commented 3 years ago

Software seems to run fine, able to consume documents placed into the consume directory, but when I came back 2 days later to view documents, no documents are returned with an error code of 500. Debug on displays the following for these requests:

image

Here is the text output from the error:

Environment:

Request Method: GET
Request URL: https://paperless-ng.mydomain.com/api/tags/?page=1&page_size=100000

Django Version: 3.1.3
Python Version: 3.8.5
Installed Applications:
['whitenoise.runserver_nostatic',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'corsheaders',
 'django_extensions',
 'paperless',
 'documents.apps.DocumentsConfig',
 'paperless_tesseract.apps.PaperlessTesseractConfig',
 'paperless_text.apps.PaperlessTextConfig',
 'paperless_mail.apps.PaperlessMailConfig',
 'django.contrib.admin',
 'rest_framework',
 'django_filters',
 'django_q']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 413, in execute
    return Database.Cursor.execute(self, query, params)

The above exception (no such column: documents_tag.slug) was the direct cause of the following exception:
  File "/usr/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/usr/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/lib/python3.8/site-packages/rest_framework/mixins.py", line 40, in list
    page = self.paginate_queryset(queryset)
  File "/usr/lib/python3.8/site-packages/rest_framework/generics.py", line 171, in paginate_queryset
    return self.paginator.paginate_queryset(queryset, self.request, view=self)
  File "/usr/lib/python3.8/site-packages/rest_framework/pagination.py", line 218, in paginate_queryset
    return list(self.page)
  File "/usr/lib/python3.8/site-packages/django/core/paginator.py", line 143, in __len__
    return len(self.object_list)
  File "/usr/lib/python3.8/site-packages/django/db/models/query.py", line 269, in __len__
    self._fetch_all()
  File "/usr/lib/python3.8/site-packages/django/db/models/query.py", line 1308, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/lib/python3.8/site-packages/django/db/models/query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/usr/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
    cursor.execute(sql, params)
  File "/usr/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/usr/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 413, in execute
    return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /api/tags/
Exception Value: no such column: documents_tag.slug
jonaswinkler commented 3 years ago

What version? Docker or bare metal?

Edit:

This is a database field that has been removed in version 0.9.6, since it was not used anywhere. It's possible that you're using a database that has once been used with 0.9.6 and beyond on version 0.9.5 or prior, causing this error about missing database fields.

alex-phillips commented 3 years ago

Would something like this be taken care of via a migration in the future? It's likely that I installed this back with an older version but have since upgraded the code. Running python3 manage.py migrate shows everything up-to-date.

alex-phillips commented 3 years ago

Also, is there somewhere in the UI or code that will tell me which version I'm currently running?

jonaswinkler commented 3 years ago

Version is shown in the bottom left corner:

image

This was added in 0.9.7. Version is also listed in the code, at src/paperless/version.py.

Updating database schemas is already taken care of automatically when using docker. If running bare metal, the migrate script has to be invoked manually on updates.

Please check the version you're running. I suspect you're on an older version and used the migrate script with a newer version, thus removing the database field. Downgrades are possible, but you'd need to manually determine which database version to revert to. If you need info on that, I can provide that if necessary.

alex-phillips commented 3 years ago

Yes, I was invoking the migration script manually before every startup. Will rebuild with latest code and see what I get. Thanks for the info.

jonaswinkler commented 3 years ago

Is this resolved?

alex-phillips commented 3 years ago

Yes, thanks.