I followed this tutorial:
to get a Django app deployed to Google App Engine. It's there, it's working, but I need to run migrations and create a user. How am I supposed to run manage.py
on those servers? I found how to SSH to them from the Google Cloud Platform console, but once I'm in the server, I can't find how to load the correct Python environment and/or run manage.py
.
I also read Running Django in the App Engine Flexible Environment which doesn't explain how to do it and their configuration file seems to assume database credentials will end up in the git repo for the application, which is a big nono. I'm not doing that, which means connecting to the production database from my workstation is cumbersome.
If this was Heroku, for example, I would do this on my dev workstation:
heroku run python manage.py migrate
or
heroku run python manage.py createsuperuser
and it would execute those commands in the server. I'm trying to do the same with Google App Engine Flexible (as well as Standard).
Best Answer
Perhaps this is useful for someone else who encounters this. It is certainly advisable to use @George's answer for normal operation, but in a pinch you can shell into run a python command from App Engine. I recently had to for debugging purposes. I used the SSH access in App Engine -> Instances in the GCP Control Panel. In my case I was using the flex environment which runs docker inside an VM instance so there are a few steps.
docker ps
. In my case my Django app was running in a container calledgaeapp
.docker exec -it gaeapp /bin/bash
python manage.py help
NOTE: These environments should be considered ephemeral and you should not make this part of any consistent workflow. When an App Engine instance is changed from debug mode back to normal operation it is very likely it will be destroyed and a new instance will replace it. This means any files generated will be lost. It also means any files generated will only exist on one of potentially many VM instances.