Entity framework 错误:无法更新数据库以匹配当前模型,因为存在挂起的更改

Entity framework 错误:无法更新数据库以匹配当前模型,因为存在挂起的更改,entity-framework,Entity Framework,我正在按照开发人员教程安装应用程序,但在打开web时会出现此错误 我对编程一无所知。我读了所有与这个主题相关的帖子,但我无法解决我的问题。随信附上我的资料 Web错误: 无法更新数据库以匹配当前模型,因为存在 已禁用挂起的更改和自动迁移。要么写下 对基于代码的迁移的挂起模型更改或启用自动 迁移。将DbMigrationsConfiguration.AutomaticMiggrationsEnabled设置为 true以启用自动迁移。描述:一个未处理的 执行当前web请求期间发生异常。 请查看堆

我正在按照开发人员教程安装应用程序,但在打开web时会出现此错误

我对编程一无所知。我读了所有与这个主题相关的帖子,但我无法解决我的问题。随信附上我的资料

Web错误: 无法更新数据库以匹配当前模型,因为存在 已禁用挂起的更改和自动迁移。要么写下 对基于代码的迁移的挂起模型更改或启用自动 迁移。将DbMigrationsConfiguration.AutomaticMiggrationsEnabled设置为 true以启用自动迁移。描述:一个未处理的 执行当前web请求期间发生异常。 请查看堆栈跟踪以了解有关错误和错误的更多信息 它起源于代码的地方

例外情况详情: System.Data.Entity.Migrations.Infrastructure.AutomaticMigrationsDisabledException: 无法更新数据库以匹配当前模型,因为存在 已禁用挂起的更改和自动迁移。要么写下 对基于代码的迁移的挂起模型更改或启用自动 迁移。将DbMigrationsConfiguration.AutomaticMiggrationsEnabled设置为 true以启用自动迁移

源错误: 在执行当前web请求期间生成了未经处理的异常。关于货物来源和位置的信息 可以使用下面的异常堆栈跟踪来识别异常

堆栈跟踪:

Web.Config



有几种处理此问题的方法,并且可能有多个问题导致此问题

但您可以尝试这种方法,首先
添加迁移
,并将其命名为

当你的
迁移
被创建时,检查它是否包含任何代码,如果它包含任何额外的或重复的代码,只需删除它

应该是这样的:

public partial class Empty : DbMigration
{
    public override void Up()
    {
    }

    public override void Down()
    {
    }
}

现在就试试。

非常感谢您的回复! 对不起,我的问题是,我对这个问题一无所知。 我应该如何执行添加迁移命令? 根据我正在阅读的内容,我从VisualStudio>PackageManager控制台输入并执行该命令。在这样做的过程中,他通知我以下情况:

PM>添加迁移。 cmdlet在命令管道位置1添加迁移。 提供以下参数的值: 名称:空 正在运行的命令已停止,因为首选项变量已更改。“ErrorActionPreference”或公共参数设置为Stop:找不到路径“C:\Users\Administrator\Source\Repos\VsomMonitoringTool\http:\localhost\VsomMonitoringTool”,因为它不存在。 PM>

打开应用程序代码并执行命令的正确方法是什么

<?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>
  <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="VsomMonitoringToolConnectionString" connectionString="Data Source=localhost\VsomMonitoringDB;Initial Catalog=VsomMonitoringToolDB;User ID=sa;Password=M0n1t0r1ng" providerName="System.Data.SqlClient"/>
    <add name="VsomMonitoringToolConnectionString_DatabasePublish" connectionString="Data Source=localhost\VsomMonitoringDB;Initial Catalog=VsomMonitoringToolDB;User ID=sa;Password=M0n1t0r1ng" providerName="System.Data.SqlClient"/>
  </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 targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
    <membership defaultProvider="SimpleMembershipProvider">
      <providers>
        <clear/>
        <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
      </providers>
    </membership>
    <roleManager enabled="true"/>
  </system.web>
  <!--<system.webServer>
    <modules>
      <remove name="FormsAuthentication" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
  </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.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.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>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"/>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
    <contexts>
      <context type="VsomMonitoringTool.DataAccess.VsomMonitoringToolContext, VsomMonitoringTool.DataAccess">
        <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[VsomMonitoringTool.DataAccess.VsomMonitoringToolContext, VsomMonitoringTool.DataAccess], [VsomMonitoringTool.DataAccess.Migrations.Configuration, VsomMonitoringTool.DataAccess]], EntityFramework, PublicKeyToken=b77a5c561934e089">
          <parameters>
            <parameter value="VsomMonitoringToolConnectionString_DatabasePublish"/>
          </parameters>
        </databaseInitializer>
      </context>
    </contexts>
  </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>
<!--ProjectGuid: {465DCAD8-36C2-40E2-A742-9EC8BFCA8B9C}-->
public partial class Empty : DbMigration
{
    public override void Up()
    {
    }

    public override void Down()
    {
    }
}