简体   繁体   English

EF代码优先-从Azure门户运行更新数据库

[英]EF Code First - run Update-Database from Azure portal

I am currently looking at the best way to update our database on Azure. 我目前正在寻找在Azure上更新数据库的最佳方法。 Running Visual Studio to just run " Update-Database " command seems a bit cumbersome. 运行Visual Studio只运行“ Update-Database ”命令似乎有点麻烦。 Is there a way to deploy to Azure and then from Azure portal run the " Update-Database " command? 有没有一种方法可以部署到Azure,然后从Azure门户运行“ Update-Database ”命令? Or is this just a standard way even when updating production database? 还是在更新生产数据库时这只是一种标准方法?

As already answered, you may setup your application to automatically apply new migrations to the database on startup. 正如已经回答的那样,您可以将应用程序设置为在启动时自动将新迁移应用于数据库。

Another way is to setup release process using Visual Studio Team Services and then setup database migration using powershell. 另一种方法是使用Visual Studio Team Services设置发布过程,然后使用powershell设置数据库迁移。 Some details available here: VSTS Build Task that runs script on multiple shards 此处提供一些详细信息: 在多个分片上运行脚本的VSTS构建任务

I'm not sure about running the powershell commands from azure portal directly. 我不确定直接从azure门户网站运行powershell命令。

However you could use System.Data.Entity.MigrateDatabaseToLatestVersion to do this for you automatically for deployments to azure. 但是,您可以使用System.Data.Entity.MigrateDatabaseToLatestVersion自动为您执行此操作,以进行天蓝色部署。 This can be automatically added to your web.config, if you select update-database in the publish profile wizard. 如果您在发布配置文件向导中选择了update-database,则可以将其自动添加到web.config中。 Details on how to do this can be found here 有关如何执行此操作的详细信息,请参见此处

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://docs.microsoft.com/zh-cn/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-在asp-net-mvc应用程序中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM