我正在尝试从Package Manager控制台中为Visual Studio 2013中的项目启用Code First迁移。 (上下文:我正在尝试从本教程(https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/preparing-databases)中了解Web部署)
我输入:
PM>启用迁移
并获得以下信息:
> Checking if the context targets an existing database...
> System.TypeInitializationException: The type initializer for
> 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an
> exception. ---> System.TypeInitializationException: The type
> initializer for 'System.Data.Entity.Internal.AppConfig' threw an
> exception. ---> System.Configuration.ConfigurationErrorsException:
> Configuration system failed to initialize --->
> System.Configuration.ConfigurationErrorsException: Unrecognized
> configuration section compilation. The type initializer for
> 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an
> exception.
我已经尝试了其他Stack Overflow帖子(以及ASP.NET论坛)建议的内容,但是没有任何效果。其他帖子建议Web.config文件可能出了点问题,但是我所做的任何更改都没有解决该错误。
这是我的Web.config文件的开头:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
答案 0 :(得分:0)
我将此代码段添加到了Web.config文件中,但是将其放置在错误的位置:
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
它应该是system.web的子级,而不是位置和运行时之间。