Docker can't connect my mysql container with djngo container

I have two separate container. When I am trying to connect MySQL with my Django container I am getting this error:

    django_farhyn  |     super().__init__(*args, **kwargs2)
    django_farhyn  | django.db.utils.OperationalError: (2005,

 "Unknown server host 'mysql' (-2)")  

This docker compose file for mysql , phpmyadmin and using for others services:

version: '3'

services:
  mysql:
    image: mysql:8
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_USER: test
      MYSQL_PASSWORD: test
      MYSQL_DATABASE: testdb
    ports:
      - "3306:3306"
    restart: always

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    environment:
      PMA_HOST: mysql
      MYSQL_ROOT_PASSWORD: test
    ports:
      - "8080:80"
    depends_on:
      - mysql
    restart: always

This docker compose file for only django project

version: '3'

services:
  django_farhyn:
    build: .
    container_name: django_farhyn
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"  # Django application port mapping

here my db settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': config('MYSQL_DATABASE', default=''),
        'USER': config('MYSQL_USER', default=''),
        'PASSWORD': config('MYSQL_PASSWORD', default=''),
        'HOST':   'mysql',
        'PORT': '3306',
    }
}

I don’t know where I am doing mistake and struggling from few hours for connect mysql container with my django docker container.

Each compose project gets its own Docker network and the service name (or container name) as domain name works only when the containers are on the same network.

So you will need to create an external network and connect both compose projects to the same external network. At least connect the services that need to communicate with eachother.

I have my own example here

In p06web1 and p06web2 only the one container is connected to the external proxy network, but in the p06proxy project I changed the default network.