I raise a container with my Django-based App and another container with PostgreSQL, linked to each other network-wise, using docker-compose
.
If I run the makemigrations
outside of a bash session inside my application docker container (linked to the PostgreSQL container), like this:
python manage.py makemigrations myapp
I get the following exception:
django.db.utils.OperationalError: could not
translate host name "db" to address: nodename
nor servname provided, or not known
Which makes sense: I don't have any instance (and configuration) of PostgreSQL outside of the container execution context.
From what I understand from past experience with other languages, and also other posts like this one it would be desirable for me to run makemigrations
and commit it.
Which would be the best approach to create and commit the migration files:
- Should I try to expose the PostgreSQL container and change the
settings.py
DATABASE
to be able to run themakemigrations
command from a local bash session? - Should I copy the
makemigrations
result executed from inside the container, into my repository and then commit it? - Should I not worry about not commiting the migrations, and instead make them and run them with a
docker-entrypoint.sh
approach (example)? - Any other option?