gpt4 book ai didi

django - 如何在 Django 应用程序的 CI 中处理迁移

转载 作者:太空狗 更新时间:2023-10-29 14:44:55 27 4
gpt4 key购买 nike

我们有一个用于 django 应用程序的 git 持续集成环境。

有时我们需要对我们的模型进行修改并将更改迁移到数据库中(pre/pro)。

在我们的钩子(Hook)中我们做:

python manage.py migrate

它获取之前在我们的本地开发环境中创建的迁移并应用它们。但我注意到有时 migrate 会要求用户交互。即:

makemigrations(本地开发)

(project-name-develop)lostcitizen@project-name:~/dev/project-name/project-name.git$ ./manage.py makemigrations
Did you rename publication.writer to publication.author (a ForeignKey)? [y/N] y
Migrations for 'publications':
0017_auto_20151117_1050.py:
- Rename field writer on publication to author

迁移(远程)

(project-name-develop)lostcitizen@project-name:~/dev/project-name/project-name.git$ ./manage.py migrate
Skipping creation of NoticeTypes as notification app not found
Operations to perform:
Synchronize unmigrated apps: landing, about, publications, [...]
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying publications.0016_auto_20151116_1650... OK
Applying publications.0017_auto_20151117_1050... OK
The following content types are stale and need to be deleted:

publications | hashtag

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

Type 'yes' to continue, or 'no' to cancel: yes

我的问题是如何处理这个以确保自动化部署“安全”?我可以手动完成,但我想从其余的开发人员工作流程中抽象出来。

我认为在 git hook 中请求用户交互是不可能的,所以我还是使用了这个:

yes | python manage.py migrate

但我认为使用它并不安全。你怎么看?

问候,

最佳答案

Django commands有一个 --noinput 开关来帮助解决这种情况。 Migrate 也支持它(参见 python manage.py migrate --help)

关于django - 如何在 Django 应用程序的 CI 中处理迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33755189/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com