gpt4 book ai didi

postgresql - 配置 PyCharm 以使用 docker-compose

转载 作者:行者123 更新时间:2023-11-29 13:21:10 33 4
gpt4 key购买 nike

我使用 docker 和 docker-composer 设置了 django-cookiecutter 模板。它带有预配置的 django 管理命令(runserver、migrate 等)

当我尝试使用其中任何一个时,我得到以下信息:

ad381d177c42:python -u /opt/.pycharm_helpers/pycharm/django_test_manage.py test . /appTesting started at 2:17 ...Creating test database for alias 'default'.../usr/local/lib/python3.5/site-packages/environ/environ.py:608: UserWarning: /app/config/settings/.env doesn't exist - if you're not configuring your environment separately, create one.  "environment separately, create one." % env_file)/usr/local/lib/python3.5/site-packages/django/db/backends/postgresql/base.py:248: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the default database instead.  RuntimeWarningTraceback (most recent call last):  File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection    self.connect()  File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 171, in connect    self.connection = self.get_new_connection(conn_params)  File "/usr/local/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection    connection = Database.connect(**conn_params)  File "/usr/local/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect    conn = _connect(dsn, connection_factory=connection_factory, async=async)psycopg2.OperationalError: could not connect to server: No such file or directory    Is the server running locally and accepting    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

docker-compose up 运行良好。

这是docker-compose.yml:

version: '2'volumes:  postgres_data_dev: {}  postgres_backup_dev: {}services:  postgres:    build: ./compose/postgres    volumes:      - postgres_data_dev:/var/lib/postgresql/data      - postgres_backup_dev:/backups    environment:      - POSTGRES_USER=budger  django:    build:      context: .      dockerfile: ./compose/django/Dockerfile-dev    command: /start-dev.sh    depends_on:      - postgres    environment:      - POSTGRES_USER=budger      - USE_DOCKER=yes    volumes:      - .:/app    ports:      - "8000:8000"    links:      - postgres      - mailhog  pycharm:    build:      context: .      dockerfile: ./compose/django/Dockerfile-dev    depends_on:      - postgres    environment:      - POSTGRES_USER=budger    volumes:      - .:/app    links:      - postgres  mailhog:    image: mailhog/mailhog    ports:      - "8025:8025"

PyCharm 解释器配置:

django docker-compose service interpreter

pycharm docker-compose service interpreter

再一次,一切看起来都很有魅力,但在 PyCharm 中却不是 :(

如果有任何帮助,我将不胜感激!谢谢!

最佳答案

找到了问题的根源。入口点被 PyCharm 2016.3.2 忽略。

Ticket on Jetbrains bugtracker

将 PyCharm 恢复到 2016.2.3 后一切正常。

关于postgresql - 配置 PyCharm 以使用 docker-compose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41528381/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com