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

旧巷老猫 提交于 2019-12-05 18:43:16

问题


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 ...

... 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


回答1:


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.




回答2:


Try this: Enable-Migrations -Force

Ensure the below is set to true AutomaticMigrationsEnabled = true;

Republish - worked for me



来源:https://stackoverflow.com/questions/12514521/entity-framework-code-first-data-migrations-not-working-with-vs2012-web-deploy

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