在Azure中部署时在EF迁移中使用更新数据库 [英] Usage of Update-Database in EF Migrations when deployed in Azure

查看:49
本文介绍了在Azure中部署时在EF迁移中使用更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我在Azure中部署了ASP.NET MVC4解决方案.
我的MSSQL Server数据库也在Azure中.

Context: I have my ASP.NET MVC4 solution deployed in Azure.
My MSSQL Server Database is also there, in Azure.

我目前以这种方式部署:

I currently deploy this way:

  1. 在web.config中,我将连接字符串从本地数据库(sdf)更改为Azure数据库( connectionString ="Server = tcp:..... database.windows.net,...")

右键单击项目名称(Visual Studio),然后发布"

Right click on project name (visual studio), and then "Publish"

所以,我的问题是:
如何在Package Manager控制台中使用 Update-database 命令?

是这样吗?

  1. 从上方执行第1步
  2. 运行更新数据库

我想确定这一点.另外,我想我应该在运行步骤2之前从Azure添加防火墙IP例外

I want to be sure about this. Also, I guess I should add the firewall IP exception from Azure before running step #2

推荐答案

是的,您是正确的.至少这对我有用:

Yes, you are right. At least that is how it worked for me:

  • 为Azure中的当前IP地址启用防火墙规则
  • 根据您的Azure数据库连接字符串更新您的web.config连接字符串.
  • 在程序包管理器控制台中运行更新数据库

另一方面,由于您的情况(我想确定这一点"),我建议在Azure中复制数据库并使用此备份测试此步骤.

On the other hand, due to your situation ("I want to be sure about this") i recommend to duplicate the database in Azure and test this steps with this backup.

希望有帮助.

编辑由于评论:

检查以下内容:在应用程序启动时通过代码触发EF迁移

这篇关于在Azure中部署时在EF迁移中使用更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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