Skip to content

Instantly share code, notes, and snippets.

@johnjameswhitman
Last active August 28, 2023 19:30
Show Gist options
  • Save johnjameswhitman/f500d385486b529fa4d1616a6cc9175d to your computer and use it in GitHub Desktop.
Save johnjameswhitman/f500d385486b529fa4d1616a6cc9175d to your computer and use it in GitHub Desktop.
Django ticket #34799 MySQL setup
version: '3'
services:
django-mysql:
image: mysql:8
container_name: django-mysql
ports:
- 43306:3306
env_file:
- local.env
MYSQL_PORT=43306
MYSQL_DATABASE=django
MYSQL_USER=django
MYSQL_PASSWORD=django
MYSQL_ROOT_PASSWORD=django
# tests/test_mysql.py settings
# Note: This example uses a root user in the DB. While this is not necessary,
# the user must have permission to CREATE DATABASE and CREATE TABLE.
import os
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "django",
"USER": "root",
"PASSWORD": os.environ["MYSQL_ROOT_PASSWORD"],
"HOST": "127.0.0.1",
"PORT": os.environ["MYSQL_PORT"],
},
"other": {
"ENGINE": "django.db.backends.mysql",
"NAME": "other",
"USER": "root",
"PASSWORD": os.environ["MYSQL_ROOT_PASSWORD"],
"HOST": "127.0.0.1",
"PORT": os.environ["MYSQL_PORT"],
},
}
SECRET_KEY = "django_tests_secret_key"
# Use a fast hasher to speed up tests.
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
USE_TZ = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment