将 Django 更新推送到生产服务器
我需要一些关于将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,
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 inmodels.py
. To actually apply the migration to the database, you need to runpython manage.py migrate my_app
. Another option would be to create migrations (by runningschemamigration
) on the development server, and then copy over the migration files to the production server and apply migrations by runningmigrate
.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.