Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Code First Data Migrations not working with VS2012 Web Deploy

I have created an MVC 3.0 application using Visual Studio 2012, .NET 4.5 and Entity Framework 5.0.

Using Code First Data Migrations, I am able to correctly propagate model changes to my local test database, but I can't figure out how to get this to work when deploying to my staging and production servers using Web Deploy.

I have read the following article ...

http://msdn.microsoft.com/en-us/library/dd394698(v=vs.110)#dbdacfx

... which explains what's supposed to happen, but it's not working for me, as Web Deploy seems unable to detect that I am using Entity Framework. The tutorial shows a checkbox to enable execution of Code First Migrations ...

Web Deploy Publish Dialog

... but my dialog shows the only Update Database checkbox for each database.

I have read that, in order for Visual Studio to detect the use of an Entity Framework context, the Web.config must include an element that defines it. Here's mine:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />

    <contexts>
        <context type="MyContext, MyAssembly">
            <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[MyContext, MyAssembly], [MyConfig, MyAssembly]], EntityFramework">
                <parameters>
                    <parameter value="MyConnectionStringName"/>
                </parameters>
            </databaseInitializer>
        </context>
    </contexts>
</entityFramework>

Any suggestions would be greatly appreciated.

Thanks,

Tim

like image 518
Tim Coulter Avatar asked Sep 20 '12 14:09

Tim Coulter


1 Answers

I have discovered the solution to this problem through experimentation.

In fact, my MVC application was created by VS2012 by converting from a VS2010 solution. Since the conversion process did not report any issues, I assumed that it had correctly converted everything, including the publishing profiles.

However, I discovered that the problem was in the conversion of these profiles and, unless I manually edit their XML files, there is apparently no way to get old imported profiles to participate in Code First Migrations.

Simply creating new publishing profiles in the converted solution results in the expected behavior.

like image 122
Tim Coulter Avatar answered Nov 09 '22 23:11

Tim Coulter