I am using docker-compose along with django and mysql, and I want in the custom entrypoint of django I want to do tests via python manage.py test.
Since I am connected to mysql, by default it goes to look for the database test_NAMEDATABASE, but it doesn't find it.
So I tried to create it as it says here, but I have several problems with permissions.
I think this is a very common situation, how did you solve it?
This is my mysql service in docker-compose.yml:
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
ports:
- 3306:${MYSQL_DATABASE_PORT}
environment:
- MYSQL_RANDOM_ROOT_PASSWORD
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_DATABASE
- MYSQL_DATABASE_HOST
- MYSQL_DATABASE_PORT
volumes:
- mysql_data:/var/lib/mysql
And this is my settings.py settings in django:
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('MYSQL_DATABASE'),
'USER': os.environ.get('MYSQL_USER'),
'PASSWORD': os.environ.get('MYSQL_PASSWORD'),
'HOST': os.environ.get('MYSQL_DATABASE_HOST'), # Or an IP Address that your DB is hosted on
'PORT': os.environ.get('MYSQL_DATABASE_PORT')
}
It gives me this error when I try to manually create the database "test_NAMEDATABASE" inside the mysql container: "Access denied for user 'django'@'%' to database 'test_NAMEDATABASE"
- MYSQL_PASSWORD: passwordet c.