ASP.NET无法启用迁移

阳台

我在启用ASP.net MVC项目上的迁移时遇到问题。任何人都请帮忙。错误如下:

PM> Enable-Migrations -ContextTypeName HRHR.Models.ListofvacanciesEntities 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. (C:\Users\Taras\documents\visual studio 2015\Projects\HRHR\HRHR\tmpAE68.tmp line 7)
       at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
       at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
       at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       --- End of inner exception stack trace ---
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
       at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
       at System.Configuration.ConfigurationManager.get_ConnectionStrings()
       at System.Data.Entity.Internal.AppConfig..ctor()
       at System.Data.Entity.Internal.AppConfig..cctor()
       --- End of inner exception stack trace ---
       at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
       at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
       at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..cctor()
       --- End of inner exception stack trace ---
       at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..ctor()
       at HRHR.Migrations.Configuration..ctor() in C:\Users\Taras\documents\visual studio 2015\Projects\HRHR\HRHR\Migrations\Configuration.cs:line 10
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
       at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
       at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldInitialCreate(String language, String rootNamespace)
       at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.

这是我的Configuration.cs:

namespace HRHR.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<HRHR.Models.ListofvacanciesEntities>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(HRHR.Models.ListofvacanciesEntities context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
    }
}

这是我的Web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <compilation debug="true" targetFramework="4.5">
    <assemblies>
      <add assembly="WebMatrix.Data, Version=2.0.0.0, Culture=neutral,    PublicKeyToken=31bf3856ad364e35" />
      <add assembly="WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </assemblies>
  </compilation>
  <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" />
  </configSections>
  <connectionStrings>
    <!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-HRHR-20160427123011.mdf;Initial Catalog=aspnet-HRHR-20160427123011;Integrated Security=True" providerName="System.Data.SqlClient" />-->
    <add name="ListofvacanciesEntities" connectionString="metadata=res://*/Models.DataForSystem.csdl|res://*/Models.DataForSystem.ssdl|res://*/Models.DataForSystem.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=Listofvacancies;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />    
  </appSettings>
  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" />
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>

</configuration>

我的解决方案资源管理器

阳台

我已经找到解决问题的方法。请检查您的项目是首先使用代码创建的,还是首先使用数据库创建的。如果您首先拥有数据库,那么您将遇到像我这样的问题。只需点击以下链接即可:http : //devgush.com/2014/02/24/migrating-a-project-from-database-first-to-code-first/对不起,我的英语不好。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ASP.NET MVC Nuget启用迁移

来自分类Dev

无法迁移到Asp.Net Identity / OWIN

来自分类Dev

ASP.NET Mvc项目EF代码首先启用迁移错误

来自分类Dev

从asp net 5迁移到asp net core时出错

来自分类Dev

无法在ASP.NET Core 1.0中启用跨域请求(CORS)

来自分类Dev

启用SSL后,ASP.NET Core无法以调试模式启动

来自分类Dev

在asp.net中启用和禁用无法正常运行的控件

来自分类Dev

启用asp.net核心请求验证

来自分类Dev

启用ASP.Net Core会话锁定?

来自分类Dev

使用CheckBox启用CheckBoxList?-ASP.NET

来自分类Dev

确认并启用ASP.NET身份用户

来自分类Dev

在 asp.net 中启用或禁用 div

来自分类Dev

Asp.net WebForms 启用角色

来自分类Dev

如何从SimpleMembership迁移到ASP.NET.Identity

来自分类Dev

什么是ASP.NET迁移中的“鉴别器”列?

来自分类Dev

如何在ASP Net MVC 3中运行迁移

来自分类Dev

从ASP Net 2.2迁移到3.1授权问题

来自分类Dev

从Asp.Net MVC迁移到sharepoint Apps是否很好?

来自分类Dev

如何使用 QRCoder 迁移;使用ZXing;在asp.net 中?

来自分类Dev

经典ASP代码迁移

来自分类Dev

我正在将我的asp.net网络api迁移到asp.net核心。CORS迁移

来自分类Dev

将ASP.NET MVC 5项目迁移到ASP.NET 5

来自分类Dev

从ASP.NET MVC 3迁移到ASP.NET Identity 2.0

来自分类Dev

为ASP .NET MVC中的静态资源启用CORS吗?

来自分类Dev

启用跨域ASP.net Web API

来自分类Dev

如何检查asp.net中的cookie是启用还是禁用的?

来自分类Dev

ASP.NET vNext,在Azure上启用对IIS 8的压缩?

来自分类Dev

单击ASP.NET按钮时在Gridview中启用Linkbutton

来自分类Dev

在ASP.NET和Sharepoint 2010中启用SessionState问题