python - LINE 1: ..." 时区 NOT NULL 的时间戳,"attributes" hstore NOT
问题描述
我找到了一个 Django 项目,但未能通过以下方式在 Docker 容器中运行:
git clone https://github.com/hotdogee/django-blast.git
$ cat requirements.txt
在此文件中,必须更新以下依赖项:- 海带==3.0.30
- 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/
因为docker-compose.yml
我使用:
version: "3"
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
dbi5k:
image: postgres
volumes:
- ./data/dbi5k:/var/lib/postgresql/data
environment:
- POSTGRES_DB=django_i5k
- POSTGRES_USER=django
- 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
我不得不改变:
$ vim i5k/settings_prod.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': '5432',
}
}
和
$ vim i5k/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_i5k',
'USER': 'django',
'PASSWORD': 'postgres',
'HOST': 'dbi5k',
'PORT': '5432',
}
}
请在我运行后在日志下方
docker-compose build
docker-compose up
# I had to wait for 2 minutes and do CTRL+C in order to give the database to start
docker-compose up
Attaching to djangoblast_dbik_1, djangoblast_db_1, djangoblast_web_1
dbik_1 |
db_1 |
dbik_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
dbik_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
dbik_1 | 2021-05-19 10:45:54.221 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2021-05-19 10:45:55.264 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2021-05-19 10:45:55.264 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
dbik_1 | 2021-05-19 10:45:54.221 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2021-05-19 10:45:55.264 UTC [1] LOG: listening on IPv6 address "::", port 5432
dbik_1 | 2021-05-19 10:45:54.221 UTC [1] LOG: listening on IPv6 address "::", port 5432
dbik_1 | 2021-05-19 10:45:54.226 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
dbik_1 | 2021-05-19 10:45:54.231 UTC [26] LOG: database system was shut down at 2021-05-19 10:45:07 UTC
db_1 | 2021-05-19 10:45:55.271 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
dbik_1 | 2021-05-19 10:45:54.237 UTC [1] LOG: database system is ready to accept connections
db_1 | 2021-05-19 10:45:55.283 UTC [26] LOG: database system was shut down at 2021-05-19 10:45:18 UTC
db_1 | 2021-05-19 10:45:55.292 UTC [1] LOG: database system is ready to accept connections
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:29: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.UserSocialAuth doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class UserSocialAuth(models.Model, DjangoUserMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:67: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Nonce doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Nonce(models.Model, DjangoNonceMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:78: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Association doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Association(models.Model, DjangoAssociationMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:91: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Code doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Code(models.Model, DjangoCodeMixin):
web_1 |
web_1 | /code/suit/admin.py:5: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
web_1 | from django.contrib.contenttypes import generic
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:29: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.UserSocialAuth doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class UserSocialAuth(models.Model, DjangoUserMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:67: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Nonce doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Nonce(models.Model, DjangoNonceMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:78: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Association doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Association(models.Model, DjangoAssociationMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:91: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Code doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Code(models.Model, DjangoCodeMixin):
web_1 |
web_1 | /code/suit/admin.py:5: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
web_1 | from django.contrib.contenttypes import generic
web_1 |
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 |
web_1 | You have unapplied migrations; your app may not work properly until they are applied.
web_1 | Run 'python manage.py migrate' to apply them.
web_1 | May 19, 2021 - 06:45:57
web_1 | Django version 1.8, using settings 'i5k.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | /code/rest_framework_swagger/urlparser.py:4: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
web_1 | from django.utils.importlib import import_module
web_1 |
web_1 | [19/May/2021 06:46:12]"GET / HTTP/1.1" 404 5610
web_1 | [19/May/2021 06:46:12]"GET /favicon.ico HTTP/1.1" 404 5643
最后,我跑了
$ docker-compose exec web python manage.py makemigrations
Migrations for 'default':
0003_auto_20210519_1900.py:
- Alter field email on code
$ docker-compose exec web python manage.py dbshell
Password for user django:
psql (11.12 (Debian 11.12-0+deb10u1), server 13.3 (Debian 13.3-1.pgdg100+1))
WARNING: psql major version 11, server major version 13.
Some psql features might not work.
Type "help" for help.
django_i5k=# create extension hstore
django_i5k-# \q
$ docker-compose run web python manage.py migrate
Starting djangoblast_db_1 ... done
Operations to perform:
Synchronize unmigrated apps: pipeline, postgres, staticfiles, admindocs, axes, messages, rest_framework_swagger, proxy, suit, rest_framework, filebrowser
Apply all migrations: default, sessions, admin, app, sites, auth, captcha, contenttypes, blast, data, webapollo
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying data.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 221, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 147, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
schema_editor.create_model(model)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 282, in create_model
self.execute(sql, params or None)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 107, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: type "hstore" does not exist
LINE 1: ..." timestamp with time zone NOT NULL, "attributes" hstore NOT...
我错过了什么?
先感谢您
解决方案
我使用了这个解决方案
version: "3"
services:
dbik:
image: postgres
volumes:
- ./data/dbik:/var/lib/postgresql/data
- ./scripts/install-extensions.sql:/docker-entrypoint-initdb.d/install-extensions.sql
environment:
- POSTGRES_DB=django_i5k
- POSTGRES_USER=django
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- dbik
links:
- dbik
$ cat scripts/install-extensions.sql
CREATE EXTENSION hstore;
docker-compose up --build
我用了之后docker-compose run web python manage.py migrate
推荐阅读
- swift - 手表操作系统:麦克风和音频处理
- php - Homebrew 安装的两个版本的 icu4c
- python - 尝试在 DockerFile 中安装私有仓库
- c# - 我想拆分字符串,应该使用 C# 获取特定文本
- mysql - 使用 awk 从未知数据库表中选择所有用户
- python - 如何在 for 循环中清除列表,以便我可以一遍又一遍地使用该列表
- node.js - 从 dynamoDB 项目中删除嵌套属性 - nodejs
- azure - 将 Cosmos DB(作为服务端点)作为后端服务器与应用程序网关连接
- powerbi - 如果没有值,如何显示日期
- pug - 如何在另一个 Mixin 的“Rest Arguments”中传递和插入 Mixin?