How to make Django migrations on Google Cloud Platform?

后端 未结 1 1133
长发绾君心
长发绾君心 2021-02-06 15:24

I would like to host my app on Google App Engine and have a Google SQL instance for the database. The main part of the app is an API built with Django Rest Framework. I asked Go

相关标签:
1条回答
  • 2021-02-06 15:49

    That's a good practice indeed to have a second CloudSQL to perform your migration onto. I'd suggest to:

    1. Deploy the new App Engine version which uses the new db schema but don't direct traffic to it yet (use gcloud app deploy --no-promote)
    2. Clone your CloudSQL instance to create a new one where you'll run the migration
    3. On your local machine, configure the Cloud SQL Proxy to point to this new CloudSQL instance and run python manage.py migrate
    4. Once the migration has finished, direct traffic to the new App Engine version.

    In a production environment your new CloudSQL instance will lack the data written to the first instance while you were performing steps 2 to 4. The easiest solution to avoid this situation altogether is to stop your App Engine app during the migration. If you cannot afford some downtime though, you'll need to track the changes made to the first instance after you've cloned it and apply these changes manually to the new instance.

    0 讨论(0)
提交回复
热议问题