Execute Code first Migration

2019-08-11 14:12发布

I have installed Windows 8.1 pro and moved all MVC projects to new work-space using VS 2013 Community Edition. All projects were using code first migration. Database Publishing was also done using code first migration. All was running fine before I updated my machine.

But Now when I publish web application to remote servers, 'Publish Web' dialog box not showing "Execute Code first Migration", Instead its showing "Update database" for updating database. And when I close it, It modifies the publish files for DB First. It seems that some global setting enforcing it to the following code:

 <Objects xmlns="">
        <ObjectGroup Name="DefaultConnection" Order="1" Enabled="False">
          <Destination Path="" />
          <Object Type="DbDacFx">
            <PreSource Path="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MVC-20140923125211.mdf;Initial Catalog=MVC-20140923125211;Integrated Security=True" includeData="False" />
            <Source Path="$(IntermediateOutputPath)AutoScripts\DefaultConnection_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
          </Object>
          <UpdateFrom Type="Web.Config">
            <Source MatchValue="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MVC-20140923125211.mdf;Initial Catalog=aspnet-MVC-20140923125211;Integrated Security=True" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
          </UpdateFrom>
        </ObjectGroup>
      </Objects>

Its strange why "Execute Code first Migration" is not shown for all my projects.

This behavior is same for all my other projects too.

The App_Data databases also not opening. So I changed connectionString' datasource from Data Source=(LocalDb)\v11.0 to Data Source=(LocalDb)\MSSQLLocalDB (MSSQL Sever 2014 express). Changing DataSource worked for opening database though.

I tried the solutions:

I tried solutions above few months back. That time the points above worked but now nothing works.

Is there any solution available for this? I wasted my whole day and still not found solution.

3条回答
该账号已被封号
2楼-- · 2019-08-11 14:41

I found a temporary solution for this. Manually replacing all ConnectionString name (Defaultconnection) to context name "ApplicationDbContext" without namespaces solved the problem.

查看更多
时光不老,我们不散
3楼-- · 2019-08-11 14:49

You might find this helpful:

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

I myself am still trying to find a simple way to deal with migrations.

查看更多
手持菜刀,她持情操
4楼-- · 2019-08-11 14:59

You need to install the Visual Studio update 4. Go to Extensions and updates under tools.

查看更多
登录 后发表回答