Entity Framework 6.0 Code First Migrations to Azure SQL DB not working.

asp.net-mvc azure ef-migrations entity-framework

Question

I am trying to create an ASP.NET MVC site loosely based on this tutorial. http://www.windowsazure.com/en-us/develop/net/tutorials/web-site-with-sql-database/

I am using VS2013 preview which gave me the option to create an ASP.NET MVC 5 site. Also, using the following packages:

EntityFramework 6.0.0-rc1

Microsoft.AspNet.Identity.Core" 1.0.0-alpha1

Microsoft.AspNet.Identity.EntityFramework 1.0.0-alpha1

After configuring a website and associating it with a database in Azure, I proceeded to run the following commands in the package manager console:

enable-migrations -ContextTypeName IdentityDbContext

add-migration Initial

When I published to Azure with the database specified and the "Execute Code First Migrations" checkbox checked, the site deployed properly, but after inspecting my DB, the migrations didn't run. My migrations had been successful previously on a site with ASP.Net MVC 4 and EF 5.0.

I would guess the problem is that EF 6 is ignoring the connection string that is set during publishing, but I cannot understand why.

Any help would be appreciated. Thank you.

1
9
9/17/2013 6:29:08 AM

Accepted Answer

This guide looks comprehensive: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application

The key part being "Execute Code First Migrations (runs on application start)"

I hope that helps.

7
11/11/2013 11:09:18 PM

Popular Answer

This question is already marked as answered but while I was looking for information for my own deployment on Azure, I found this blog extremely helpful. Then I'd like to share because it concisely covers all the possible scenarios for your deployments using Code First Migrations.

http://blogs.msdn.com/b/webdev/archive/2014/04/09/ef-code-first-migrations-deployment-to-an-azure-cloud-service.aspx

Hope that helps for new searchers.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow