I am using Dockerized Django to connect with MySql but I'm getting the following error:
File "/usr/local/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
I also Have tried every single possible solution on stackoverflow and google, but nothing seems to work. I suspect the MySQL driver within the docker container needs to be updated/configured correctly.
Does anyone have any suggestions on what are the exact steps to undertake to fix it? THANKS!
ENVIRONMENT
MacOS 10.15.7.
requirements.txt:
Django==3.1.3
djangorestframework==3.12.2
mysqlclient==2.0.1
django-mysql==3.9
django-cors-headers==3.5.0
pika==1.1.0
Dockerfile:
FROM python:3.9
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app
CMD python manage.py runserver 0.0.0.0:8000
docker-compose.yml:
version: '3.8'
services:
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- db
db:
image: mysql:5.7.22
restart: always
environment:
MYSQL_DATABASE: !@#$%
MYSQL_USER: root
MYSQL_PASSWORD: ******
MYSQL_ROOT_PASSWORD: ******
volumes:
- .dbdata:/var/lib/mysql
ports:
- 33066:3306