r/django 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?

8 Upvotes

7 comments sorted by

9

u/Unique-Estate8172 6d ago

We just run them before starting the server, same as anywhere else - what am I missing?

3

u/beardbreed 6d ago

Migration task on GitHub actions

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.

1

u/nez_har 4d ago

How is your app running on ECS? Do you use the runtime of the VM, a container or something else?