在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:
-
在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步
- 运行更新数据库
我想确定这一点.另外,我想我应该在运行步骤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迁移