During local development I have a Docker container running MariaDB and I run Django on the host computer, macOS. This works and I can run tests successfully. But if I add the --parallel
flag when running tests I run into problems.
First I had to brew install mysql-client
which was needed to get mysqldump
working.
But now I’ve run into errors with authentication which I’m stumped by, given that the non-parallel tests can successfully create and destroy a test database:
$ source .env && ./manage.py test --settings=myproject.settings.tests --parallel
Found 46 test(s).
Creating test database for alias 'default'...
Cloning test database for alias 'default'...
ERROR 1045 (28000): Access denied for user 'dbuser'@'localhost' (using password: YES)
mysqldump: Got error: 1045: Access denied for user 'dbuser'@'localhost' (using password: YES) when trying to connect
My docker-compose.yml
is:
services:
db:
container_name: myproject_db
env_file: .env
image: mariadb:10.6.17
ports:
- 5556:3306
restart: unless-stopped
volumes:
- ./docker/db/init:/docker-entrypoint-initdb.d
- mysql_data:/var/lib/mysql
volumes:
mysql_data:
.env
is
# For use in Django:
export DATABASE_URL='mysql://dbuser:dbpw@localhost:5556/myproject'
# For use in Docker:
export MYSQL_USER=dbuser
export MYSQL_PASSWORD=dbpw
export MYSQL_DB=myproject
And my settings include:
DATABASES = {"default": dj_database_url.config()}
DATABASES["default"]["ENGINE"] = "django.db.backends.mysql"