Categories
Python Answers

How to perform Python Django database migrations when using Docker-Compose?

Spread the love

To perform Python Django database migrations when using Docker-Compose, we can add the migrate command in a script.

For instance, in docker-entrypoint.sh, we add

python manage.py collectstatic --noinput
python manage.py migrate
python manage.py runserver 0.0.0.0:8000

to collect static files with

python manage.py collectstatic --noinput

We run the database migrations with

python manage.py migrate

And then we start the server with

python manage.py runserver 0.0.0.0:8000

Then we run the script during docker-compose by running the script with a command by putting it in the command property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *