ASP.NET MVC 4,迁移-如何在生产服务器上运行“更新数据库" [英] ASP.NET MVC 4, Migrations - How to run 'update-database' on a production server

本文介绍了ASP.NET MVC 4,迁移-如何在生产服务器上运行“更新数据库"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用包管理器在本地运行"update-database -verbose".

I can use package manager to run 'update-database -verbose' locally.

可能是一个愚蠢的问题,但我无法在线找到它-部署网站后-如何在服务器上手动运行它?

Probably a stupid question but I can't find it online - once my website is deployed - how can I run this manually on the server?

其次-为将数据库迁移部署到生产环境,您还建议其他什么策略?它们将是更好的选择吗?

Secondarily - what other strategies would you recommend for deploying database migrations to production - and how would they be preferable?

谢谢

推荐答案

您有几个选择:

  • 您可以使用update-database -script生成SQL命令以更新服务器上的数据库
  • 您可以使用 migrate.exe 可执行文件,位于/packages/EntityFramework5.0.0/tools/migrate.exe上的程序包文件夹中.过去,我已经在Jet Brains的Team City Build Server中成功使用了它,并通过我的部署脚本来设置迁移.
  • 如果您使用的是IIS Web Deploy,则可以告诉服务器在发布后执行迁移(请参见下图)
  • 您可以设置自动迁移,但是我更愿意控制何时发生:)
  • You could use update-database -script to generate the SQL commands to update the database on the server
  • You could use the migrate.exe executable file that resides in the package folder on /packages/EntityFramework5.0.0/tools/migrate.exe. I've used it successfully in the past with Jet Brains' Team City Build Server to setup the migrations with my deploy scripts.
  • If you're using IIS Web Deploy you can tell the server to perform the migrations after publish (see pic below)
  • You could setup automatic migrations, but I prefer to be in control of when things happen :)

更新:此外,请查看易卜拉欣说的博客,他在Microsoft的MsBuild团队工作,对部署有一些很好的见识

Update: Also, check out Sayed Ibrahim's blog, he works on the MsBuild Team at Microsoft and has some great insights on deployments

这篇关于ASP.NET MVC 4,迁移-如何在生产服务器上运行“更新数据库"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆