将 Django 更新推送到生产服务器

发布于 2024-12-06 05:53:33 字数 484 浏览 0 评论 0原文

我需要一些关于将 Django 更新(特别是数据库更新)从开发服务器推送到生产服务器的建议。我相信更新脚本、文件等会很容易——只需将新文件从开发服务器复制到生产服务器即可。然而,数据库更新让我不确定。

对于 Django,我在初始 Web 应用程序创建期间一直使用 South 来更改数据库架构。如果我要在生产服务器上停机进行更新,我可以将所有文件复制到生产服务器。这些将包括并更改描述数据库表的 models.py 文件。然后,我可以执行 python manage.py schemamigration my_app --auto ,然后执行 python migrate my_app 以根据新的 files/models.py 更新数据库我已经复制过来了。

这是一个好的解决方案还是有更合适的方法将数据库从开发服务器更新到生产服务器?

你的想法?

谢谢

I need some advice on pushing Django updates, specifically the database updates, from my development server to my production server. I believe that updating the scripts, files, and such will be easy -- simply copy the new files from the dev server to the production server. However, the database updates are what have me unsure.

For Django, I have been using South during initial web app creation to change the database schema. If I were to have some downtime on the production server for updates, I could copy all the files over to the production server. These would include and changed models.py files which describe the database tables. I could then perform a python manage.py schemamigration my_app --auto and then a python migrate my_app to update the database based on the new files/models.py I've copied over.

Is this an OK solution or are there more appropriate ways to go about updating a database from development to production servers?

Your thoughts?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧桑㈠ 2024-12-13 05:53:34

实际上,python manage.py schemamigration my_app --auto 只会根据 models.py 中的更改创建迁移。要实际将迁移应用到数据库,您需要运行python manage.py migrate my_app。另一种选择是在开发服务器上创建迁移(通过运行 schemamigration),然后将迁移文件复制到生产服务器并通过运行 migrate 应用迁移。

当然,拥有一个源代码存储库比四处复制文件要好得多。您可以在开发服务器上创建迁移,将它们提交到存储库,在生产服务器上从存储库中提取新文件,最后应用迁移。

Actually, python manage.py schemamigration my_app --auto will only create the migration based on the changes in models.py. To actually apply the migration to the database, you need to run python manage.py migrate my_app. Another option would be to create migrations (by running schemamigration) on the development server, and then copy over the migration files to the production server and apply migrations by running migrate.

Of course, having a source code repository would be way better than copying the files around. You could create migrations on your development server, commit them to the repository, on the production server pull the new files from repository, and finally apply migrations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文