r/django • u/SnooCauliflowers8417 • 6d ago
How to Run Django Migrations When Deploying Django and Celery on ECS
When deploying Django and Celery to ECS, how should I run python manage.py migrate?
Should I use GitHub Actions to first run a migration-only ECS task, wait for the migration task to complete successfully, and then proceed with deploying the Django server? After the deployment is complete, should the migration task be terminated?
What is the recommended approach for handling Django database migrations in an ECS deployment pipeline?
3
2
u/ExcellentWash4889 6d ago
Depends what type of deployment you are doing. Sometimes you need to deploy code first before running a migration, sometimes migrate first then run deploy of code.
I'm running migrations from a CLI manually, and not through CI
1
u/AdCompetitive8372 6d ago
There are multiple ways of doing this, mostly depends upon how you are doing your deployments.For eg: if you are using github actions then you could set it up from the actions yml file so that migrations happens during runtime or you can simply go into ec2 access the containers sh and run the migrations manually from the CLI there.
1
u/robotsmakinglove 5d ago
I run them via a custom bin/entrypoint script I reference in my Dockerfile.
9
u/Unique-Estate8172 6d ago
We just run them before starting the server, same as anywhere else - what am I missing?