Django+MySQL Docker でutf8mb4を使う
code:docker-compose.yml
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: db
MYSQL_ROOT_PASSWORD: root
TZ: 'Asia/Tokyo'
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
volumes:
- mysql_data:/var/lib/mysql
- ./mysql/conf.d:/etc/mysql/conf.d
- ./mysql/initdb.d:/docker-entrypoint-initdb.d
ports:
- 3306:3306
code:mysql/conf.d/my.cnf
default-character-set=utf8mb4
default-character-set=utf8mb4
character-set-server=utf8mb4
skip-character-set-client-handshake
collation-server=utf8mb4_unicode_ci
code:settings.py
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": 'db',
"USER": 'root',
"PASSWORD": 'root',
"HOST": 'db',
"PORT": '3306',
'OPTIONS': {
'charset': 'utf8mb4',
},
}
}
参考