Usage of Update-Database in EF Migrations when deployed in Azure

大兔子大兔子 提交于 2021-01-27 05:42:34

问题


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. In web.config I change the connection string from local database (sdf) to azure database (connectionString="Server=tcp:.....database.windows.net, ...")

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

So, my question is:
How do I use the Update-database command in the Package Manager Console?

Is it this way?

  1. Same step #1 from above
  2. Run Update-Database

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


回答1:


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

  • Enable a firewall rule for your current IP Address in Azure
  • Update your web.config connection string according with your Azure Database conneciton string.
  • Run Update-Database in your Package Manager Console

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.

Hope it helps.

EDIT due to comment:

Check this out: Triggering EF migration at application startup by code



来源:https://stackoverflow.com/questions/17048910/usage-of-update-database-in-ef-migrations-when-deployed-in-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!