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 
<https://stackoverflow.com/questions/14186055/django-test-app-error-got-an-error-creating-the-test-database-permission-deni>,
 
and I even tried this <https://stackoverflow.com/a/45131868/11790764>. It 
didn't help me. 

Anyone who's been stuck at similiar problem? 

Thanks guys in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3f7e3dc9-2c16-489e-9559-5899dc60dde1n%40googlegroups.com.

Reply via email to