TandoorRecipes / recipes

Application for managing recipes, planning meals, building shopping lists and much much more!
https://docs.tandoor.dev
Other
5.34k stars 563 forks source link

"ProgrammingError at /search/" "relation "cookbook_userspace" does not exist" #2462

Closed moorsey closed 1 year ago

moorsey commented 1 year ago

Have just ran an upgrade:

docker-compose pull
docker-compose up -d --remove-orphans

Get to login page fine, but when logging in get the below traceback

Will try a fresh install later this week and re-import DB, see if that helps, but maybe I am able to manually run DB upgrade? Perhaps something was missed on first run to create new tables etc. Thought I would log in case of a wider issue

Afraid I do not recall the version I came from, ran an upgrade end of last year ish.

Environment:

Request Method: GET
Request URL: https://tandoor.xxxxxxxxxxxxxx.org/search/

Django Version: 4.1.7
Python Version: 3.10.8
Installed Applications:
['dal',
 'dal_select2',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'django.contrib.postgres',
 'oauth2_provider',
 'django_prometheus',
 'django_tables2',
 'corsheaders',
 'crispy_forms',
 'rest_framework',
 'rest_framework.authtoken',
 'django_cleanup.apps.CleanupConfig',
 'webpack_loader',
 'django_js_reverse',
 'hcaptcha',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'cookbook.apps.CookbookConfig',
 'treebeard',
 'debug_toolbar']
Installed Middleware:
['corsheaders.middleware.CorsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 '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.locale.LocaleMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'cookbook.helper.scope_middleware.ScopeMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware']

Traceback (most recent call last):
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)

The above exception (relation "cookbook_userspace" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "cookbook_userspace" WHERE...
                                          ^
) was the direct cause of the following exception:
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "/opt/recipes/cookbook/helper/scope_middleware.py", line 40, in __call__
    if request.user.userspace_set.count() == 0 and not reverse('account_logout') in request.path:
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/query.py", line 621, in count
    return self.query.get_count(using=self.db)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 559, in get_count
    return obj.get_aggregation(using, ["__count"])["__count"]
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/sql/query.py", line 544, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1398, in execute_sql
    cursor.execute(sql, params)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /search/
Exception Value: relation "cookbook_userspace" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "cookbook_userspace" WHERE...
                                          ^
smilerz commented 1 year ago

manage.py migrate

moorsey commented 1 year ago

Many thanks, no dice unfortunately! Maybe not fixable!

docker exec -it tandoor_web_recipes_1 /bin/sh
/opt/recipes # ls
CONTRIBUTERS.md    boot.sh            makemessages.cmd   mediafiles         openapitools.json  requirements.txt   venv               yarn.lock
SECURITY.md        cookbook           manage.py          nginx              recipes            staticfiles        vue
/opt/recipes # ./manage.py migrate
Traceback (most recent call last):
  File "/opt/recipes/./manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/recipes/./manage.py", line 10, in <module>
    raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
moorsey commented 1 year ago

OK, tried dropping completely, starting fresh, can get Tandoor up and running OK

Importing the DB works, but obviously there have been a load of changes, but can't force an upgrade of the DB it seems, same django error again

Will look at spinning up an older version of the image I guess for now!

Cheers

moorsey commented 1 year ago

OK, so tried 1.4.6 and 1.4.5, restore DB, same error:

The above exception (relation "cookbook_userspace" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "cookbook_userspace" WHERE... ^ ) was the direct cause of the following exception:

Very confused as to how there could be anything remaining causing an error now

moorsey commented 1 year ago

OK, think I've mixed. I went back to 1.2.7, which worked OK. I then stepped through each version, running...

docker-compose pull docker-compose up -d --remove-orphans

After each version edit, watched web container logs to make sure it completed migrations etc, rinse repeat

All booted up anyway, seems well so far....!

smilerz commented 1 year ago

Sorry venv/bin/activate needs executed first