[英]How to run Django migrations in Google App Engine Flexible deployment step?
I have a Django app up and running in Google App Engine flexible. 我已经在Google App Engine flexible中启动并运行了Django应用。 I know how to run migrations using the cloud proxy or by setting the
DATABASES
value but I would like to automate running migrations by doing it in the deployment step. 我知道如何使用云代理或通过设置
DATABASES
值来运行迁移,但是我想通过在部署步骤中执行迁移来自动运行迁移。 However, there does not seem to be a way to run a custom script before or after the deployment. 但是,似乎没有办法在部署之前或之后运行自定义脚本。
The only way I've come up with is by doing it in the entrypoint command which you can set in the app.yaml
: 我想出的唯一方法是在entrypoint命令中执行此操作,您可以在
app.yaml
进行设置:
entrypoint: bash -c 'python3 manage.py migrate --noinput && gunicorn -b :$PORT app.wsgi'
This feels a lot like doing it wrong. 这感觉很像做错了。 A lot of Googling didn't provide a better answer.
很多谷歌搜索并没有提供更好的答案。
Defining the python3 manage.py migrate
command in your app.yaml file will make it run every time a new instance is spawned and set up to serve traffic. 在app.yaml文件中定义
python3 manage.py migrate
命令将使其在每次生成新实例并设置为服务流量时运行。 Although technically this may not be an issue (no migration will happen if database schema hasn't changed) this isn't the right place to declare it. 尽管从技术上讲这可能不是问题(如果数据库架构未更改,则不会进行迁移),这不是声明它的正确位置。
You'd want this command to run once on every new version code push. 您希望此命令在每次新版本代码推送时运行一次。 This fits perfectly in a CI/CD approach.
这非常适合CI / CD方法。 There are several tutorials on the Google Cloud online documentation using Bitbucket Pipelines or Travis CI for example but you can use many other CI/CD solutions.
例如,在Google Cloud在线文档中有一些使用Bitbucket Pipelines或Travis CI的教程,但是您可以使用许多其他CI / CD解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.