-1

我正在尝试使用 Neo4j 数据库在 Django 中做一个简单的项目。我已经安装了一个django-neomodel库,设置如下:

import os
from neomodel import config

db_username = os.environ.get('NEO4J_USERNAME')
db_password = os.environ.get('NEO4J_PASSWORD')

config.DATABASE_URL = f'bolt://{db_username}:{db_password}@localhost:7687'

创建了一个模型:

class Task(StructuredNode):
    id = UniqueIdProperty()
    title = StringProperty()

添加'django_neomodel'INSTALLED_APPS,删除了默认数据库配置,当我尝试进入网站时,它会引发错误:ImproperlyConfigured at / settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details..

这是唯一的错误,因为在运行python manage.py install_labels命令后它会引发:ServiceUnavailable("Failed to establish connection to {!r} (reason {})".format(resolved_address, error)) neo4j.exceptions.ServiceUnavailable: Failed to establish connection to IPv6Address(('::1', 7687, 0, 0)) (reason [Errno 99] Cannot assign requested address).

我很确定数据库可以正常工作,因为如您所见,我可以访问它。截屏

码头工人撰写:

version: "3.9"

services:
  api:
    container_name: mm_backend
    build:
      context: ./
      dockerfile: Dockerfile.dev
    command: pipenv run python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./:/usr/src/mm_backend
    ports:
      - 8000:8000
    env_file: .env
    depends_on: 
      - db

  db:
    container_name: mm_db
    image: neo4j:4.1
    restart: unless-stopped
    ports:
      - "7474:7474"
      - "7687:7687"
    volumes:
      - ./db/data:/data
      - ./db/logs:/logs
4

1 回答 1

0

好吧,经过一些研究,我发现这篇文章Docker-compose: db connection from web container to neo4j container using bolt并且问题已经解决。

于 2021-04-05T10:12:13.590 回答