Search code examples
pythondjangodockerneo4jneomodel

Errors during configuration of the neo4j django-neomodel


I'm trying to do a simple project in Django using the Neo4j database. I've installed a django-neomodel library, set the settings as follows:

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'

created a model:

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

added 'django_neomodel' to INSTALLED_APPS, removed the default database configuration and when I try to enter the website it raises the error: ImproperlyConfigured at / settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details..

It's the only error because after running the python manage.py install_labels command it raises: 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).

I'm pretty sure that the database works correctly because as you see I can access this. screenshot

docker-compose:

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

Solution

  • Well, after some research I've found this post Docker-compose: db connection from web container to neo4j container using bolt and the problem has been solved.