简体   繁体   中英

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

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM