Monday, May 24, 2021

Re: Exception Value: relation "django_session" does not exist

You are welcome :-)

On Tue, May 25, 2021 at 3:41 AM Michał T. Lorenc <m.t.lorenc@gmail.com> wrote:
Hi,
Thank you it works.

On Tue, May 25, 2021 at 12:31 AM RANGA BHARATH JINKA <bharathjinka09@gmail.com> wrote:
hi, 

Run migrations. python manage.py makemigrations and python manage.py migrate

On Mon, May 24, 2021 at 7:20 PM Mic <m.t.lorenc@gmail.com> wrote:
Hello,
I found a Django project and failed to get it running in Docker container in the following way:

 2. `$ cat requirements.txt` in this files the below dependencies had to be updated:
    - psycopg2==2.8.6 

I have the following Dockerfile:

```
FROM python:2
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y postgresql-client
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
RUN mkdir -p /var/log/django
RUN mkdir -p /var/log/i5k
```

For `docker-compose.yml` I use:

```
version: "3"

services:
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
      - ./scripts/install-extensions.sql:/docker-entrypoint-initdb.d/install-extensions.sql

    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
    links:
      - db
```

```
$ cat scripts/install-extensions.sql 
CREATE EXTENSION hstore;
```

I had to change:

```
    $ vim i5k/settings.py
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'postgres',
            'USER': 'postgres',
            'PASSWORD': 'postgres',
            'HOST': 'db',
            'PORT': '5432',
            }
    }
```

Next, I ran `docker-compose up --build` and opened in Browser `http://localhost:8000/admin/` which caused:

```
Environment:


Request Method: GET

Django Version: 1.8.12
Python Version: 2.7.18
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.postgres',
 'axes',
 'rest_framework',
 'rest_framework_swagger',
 'pipeline',
 'app',
 'blast',
 'migrate_account',
 'suit',
 'filebrowser',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'social.apps.django_app.default',
 'captcha',
 'dashboard',
 'proxy',
 'hmmer',
 'clustal',
 'webapollo_sso',
 'drupal_sso')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'axes.middleware.FailedLoginMiddleware',
 'app.middleware.SocialAuthExceptionMiddleware')


Traceback:
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in wrapper
  254.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  222.             if not self.has_permission(request):
File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in has_permission
  162.         return request.user.is_active and request.user.is_staff
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py" in inner
  225.             self._setup()
File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py" in _setup
  376.         self._wrapped = self._setupfunc()
File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py" in <lambda>
  22.         request.user = SimpleLazyObject(lambda: get_user(request))
File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py" in get_user
  10.         request._cached_user = auth.get_user(request)
File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in get_user
  167.         user_id = _get_user_session_key(request)
File "/usr/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in _get_user_session_key
  59.     return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in __getitem__
  48.         return self._session[key]
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session
  181.                 self._session_cache = self.load()
File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in load
  21.                 expire_date__gt=timezone.now()
File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
  127.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in get
  328.         num = len(clone)
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__
  144.         self._fetch_all()
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
  965.             self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  238.         results = compiler.execute_sql()
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  840.             cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
  98.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /admin/
Exception Value: relation "django_session" does not exist
LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...
```

What did I miss?

Thank you in advance


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d671a6dc-cdc9-42ab-9c32-0ec46263e242n%40googlegroups.com.


--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/8nn2lMxFxn0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK5m317w45hABoFr_-79iXOunkQT7gnOCbcMEoGHMiY_PXm2kA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABMg7%3DmVphppQuBOvy-UAWCOd%2Bp2z1xBjjGpN6qr0iC8SX0X3Q%40mail.gmail.com.


--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK5m314yremOnPBG5zW6QWMw6SqOw0WxsRTnzvPFnqMzt92ZGA%40mail.gmail.com.

No comments:

Post a Comment