Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Migrations with Multiple Web Config Transforms

I have created an ASP.NET MVC 4 project in Visual Studio 2010 using Entity Framework 5 with migrations enabled. I have multiple web config files for different environments (Debug, Staging, Release) which will specify different database connectionStrings depending on the environment. How do I handle migrations using the Update-Database command from the Package Manager Console with the multiple config files? Each time I run this command, it defaults to the main Web.config connection string. Thanks for any help in advance.

like image 433
Brandon B. Avatar asked Feb 15 '13 14:02

Brandon B.


1 Answers

In order to try and keep things as simple as possible, the way I worked around running migrations on my remote staging and production servers, is to run the following command from the package console (data source and user/pass would change depending on which server I wanted to run the migrations against):

Update-Database -Verbose -ConnectionString "Data Source=ServerName;Initial Catalog=db;User Id=user;Password=pass;" -ConnectionProviderName "System.Data.SqlClient"

This has worked for me so far in case anyone else is looking. Thanks everyone for the comments.

like image 122
Brandon B. Avatar answered Oct 20 '22 22:10

Brandon B.