EF Code First - 从Azure门户运行Update-Database

时间:2018-04-27 10:35:30

标签: c# azure azure-sql-database

我目前正在寻找在Azure上更新数据库的最佳方法。运行Visual Studio只运行“ Update-Database ”命令似乎有点麻烦。有没有办法部署到Azure,然后从Azure门户运行“更新数据库”命令?或者,即使更新生产数据库,这只是一种标准方式吗?

2 个答案:

答案 0 :(得分:2)

如前所述,您可以将应用程序设置为在启动时自动将新迁移应用于数据库。

另一种方法是使用Visual Studio Team Services设置发布过程,然后使用PowerShell设置数据库迁移。这里提供了一些详细信息:VSTS Build Task that runs script on multiple shards

答案 1 :(得分:1)

我不确定直接从azure portal运行powershell命令。

但是,您可以使用System.Data.Entity.MigrateDatabaseToLatestVersion自动执行此操作,以便部署到azure。如果在发布配置文件向导中选择update-database,则可以将其自动添加到web.config中。有关如何执行此操作的详细信息,请访问

https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application

https://msdn.microsoft.com/en-us/library/hh829293(v=vs.113).aspx

相关问题