Home > Software design >  Should I be adding the Django migration files in the .dockerignore /.gitignore file?
Should I be adding the Django migration files in the .dockerignore /.gitignore file?

Time:11-18

This is probably a duplicate of this question.

My question is how should I approach this when working in a docker environment so for my project I have a docker-compose.yml and docker-compose-deploy.yml for my production environment and obviously migration files are generated only in the docker images and aren't included in my version control system.

How should I approach this? should I stop using Docker as my development environment and go for something like virtual environments or even machines?

CodePudding user response:

No. The migration files are there so you can update your database without destroying it and rebuilding it from scratch (or doing the sql update statements by hand).

So you definitely want to track them in your version control.

During development, a classic scenario would be

  1. write code
  2. make migrations
  3. apply migrations on your dev database
  4. test the changes locally
  5. check in and push the commit to your production server
  6. execute the migrations (so only do python manage.py migrate) in production

Edit: I forgot to answer your docker question. Usually you put your source code in a volume outside the container, that you then mount into the container. So you can do docker development like this. That way the migration files and up in your codebase and you can track it.

  • Related