Got an error creating the test databse - with mysql and docker-compose

83 views
Skip to first unread message

Gwanghyeon Gim

unread,
May 1, 2021, 9:41:34 AM5/1/21
to Django users
Hi django developers!

I have an issue with creating test database. I use mysql for db and docker compose.

I have no problem running docker containers with docker-compose, but when I run test it spits this error message.

Note that the name of django service is web, and mysql service is db.

$ docker-compose run --rm web sh -c "python manage.py test"
Creating sociallogin_web_run ... done
Creating test database for alias 'default'...
Got an error creating the test database: (1044, "Access denied for user 'myuser'@'%' to database 'test_mydb'")

my docker-compose file:
version: "3.9"

services:

db:
image: mysql:8
env_file:
- .env
command:
- --default-authentication-plugin=mysql_native_password
restart: always
# ports:
# - "3306:3306"
# volumes:
# - data:/var/lib/mysql

web:
build: .
command: >
sh -c "python manage.py wait_for_db &&
python manage.py makemigrations &&
python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
env_file:
- .env

# volumes:
# data:

my .env file looks like this:
MYSQL_ROOT_PASSWORD=rootpass
MYSQL_USER=exampleuser
MYSQL_PASSWORD=examplepass
MYSQL_DATABASE=exampledb
MYSQL_PORT=3306
SECRET_KEY=exmaple_random_characters


my settings for DATABASES

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

I looked at SO, and I even tried this. It didn't help me. 

Anyone who's been stuck at similiar problem? 

Thanks guys in advance.
Reply all
Reply to author
Forward
0 new messages