我想在 Google App Engine 上托管我的应用程序,并拥有一个用于数据库的 Google SQL 实例。该应用程序的主要部分是使用 Django Rest Framework 构建的 API。当我需要修改数据库的架构时,我向 Google Cloud 支持人员询问了在生产中进行迁移的最佳实践。由于我是 Web 开发的新手,也许这里的任何专家都有类似的经验,并且可以验证建议的过程是否是我真正可以遵循的?
For database migration best practice, you could create a separate development/test/backup instance of your Cloud SQL database. Let's say for example your DB instance for production is DB1, create a dev instance namely DB2 that has all the tables of DB1. After that, configure your app to point DB2 instance temporarily. Please make sure that both instances are in sync and updated. Then, deploy a new version of your app that points to DB2 so you can update DB1 (add new tables, columns) as your official database instance in the production environment. Then you can point it again to DB1 and update DB2.
最佳答案
使用第二个 CloudSQL 来执行迁移确实是一个很好的做法。我建议:
gcloud app deploy --no-promote
)python manage.py migrate
在生产环境中,您的新 CloudSQL 实例将缺少在您执行步骤 2 到 4 时写入第一个实例的数据。完全避免这种情况的最简单解决方案是在迁移期间停止您的 App Engine 应用程序。但是,如果您无法承受一些停机时间,则需要在克隆第一个实例后跟踪对它所做的更改,并将这些更改手动应用于新实例。
关于django - 如何在 Google Cloud Platform 上进行 Django 迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48825154/