How to run Django migrations inside kubernetes and apply changes to the database pod?

7/8/2021

I have deployed my app to Azure with Kubernetes. I have separate pods for front end, back end and database. I encountered problems when one of my database fields changed from id to userId. I have tried to update this change to my deployment database but without any luck. I logged into my back end pod and removed the existing migration file and run python manage.py makemigrations & python manage.py migrate. After these I checked that everything was ok in the migration file. After this I don't know what to do. Do I need to remove the database pod and create it again? Or how do I update the database inside the pod?

-- lr_optim
django
kubernetes

1 Answer

7/8/2021

id -> userId change is a DDL change for your DB. I suggest that you "exec" into your DB pod and start your DB shell.

kubectl exec -it mysql-pod-name bash

Then you should be able to execute your DDL statement. MySql example:

ALTER TABLE tableName
RENAME COLUMN id TO userId;
-- Rakesh Gupta
Source: StackOverflow