异常值:关系“django_session”不存在

异常值:关系“django_session”不存在

我找到了一个Django项目,但无法通过以下方式在Docker容器中运行它:

  1. git clone git clone https://github.com/NAL-i5K/django-blast.git
  2. $ cat requirements.txt在此文件中,必须更新以下依赖项:
    • psycopg2==2.8.6

我有以下 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

对于docker-compose.yml我来说:

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;

我必须改变:

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

接下来,我docker-compose up --build在浏览器中运行并打开,http://localhost:8000/admin/结果如下:

Environment:


Request Method: GET
Request URL: http://localhost:8000/admin/

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...

我错过了什么?

先感谢您

答案1

我已将 docker 与 django+postgresql 一起使用,没有任何问题,但我建议对于 postgres 使用 psycopg2 二进制文件而不仅仅是 psycopg2,并且我正在链接一个文档以获取进一步帮助点击此处

相关内容