Andrés Montoya
Andrés Montoya

Reputation: 4447

Django over Docker does not install mysqlclient

I want to integrate MySQL with Django, MySQL is running over Docker and I put the config like this to connect to the db docker with Django:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'restaurant',
        'HOST': 'db',
        'PORT': '3306',
        'USER': 'root',
        'PASSWORD': 'root',
        'default-character-set': 'utf8',
        'OPTIONS': {
            'init_command': 'SET default_storage_engine=INNODB',
        }
    }
}

But when Django is trying to connect to the mysql db, it throws me this error:

enter image description here

I tried to install mysqlclient with pip, but I have this error:

enter image description here

These are the docker-compose.dev.yml and Dockerfile configs.

If someone needs the complete code, here you can find it, and test it with docker-compose -f docker-compose.dev.yml up --build.

Thanks :).

Upvotes: 0

Views: 4079

Answers (2)

Andrés Montoya
Andrés Montoya

Reputation: 4447

Another response would be adding:

RUN apk add --no-cache bash mariadb-dev mariadb-client mariadb-libs python3-dev build-base

On the dockerfile.

Upvotes: 0

2ps
2ps

Reputation: 15946

mysqlclient has native dependencies that must be installed before you can pip install it. When running in docker, and especially in alpine, you probably want to switch over to using mysql-connector-python which is a pure python library that does not have any native dependencies l,ike mysqlclient. Update your requirements file and update your settings to use mysql.connector.django if you want to use mysql-connector-python.

Upvotes: 5

Related Questions