【问题标题】:EF Core "no migrations found" despite Migrations folder containing migration files尽管 Migrations 文件夹包含迁移文件,但 EF Core“未找到迁移”
【发布时间】:2020-02-29 02:08:30
【问题描述】:

我们有一个 .NET Core 项目,其中包含一个 Migrations 文件夹,其中包含过去通过执行 dotnet ef database update 在我们的开发数据库中成功运行的多个迁移。但是,我们现在正尝试将这些更改应用到我们的暂存数据库,但它不起作用。我们已将 ASPNETCORE_ENVIRONMENT 环境变量设置为 Staging,当我们尝试运行迁移时,它似乎正确地定位了 Staging。在我们的暂存数据库中创建了一个dbo.__EFMigrationsHistory 表,但其中没有条目。此外,当我们运行dotnet ef migrations list 时,我们会收到一条消息,上面写着“未找到迁移”。即使我们将ASPNETCORE_ENVIRONMENT 变量设置回Development,我们也会得到相同的结果。

我们已经运行了上面所有带有详细标志的dotnet ef 命令,并且没有出现任何错误。唯一看起来可疑的输出是No referenced design-time services were foundNo design-time services were found,但我们无法确定解决这些问题需要做些什么。

当我们运行dotnet ef migrations add <migration name> 时,它成功地在 Migrations 文件夹中生成了一个迁移文件,而当我们运行 dotnet ef migrations list 时,新的迁移出现了,所以看起来我们的旧迁移在正确的位置。由于某种原因,dotnet ef 没有检测到它们。

我们的.csproj 中有以下软件包:

    <PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
    <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.113">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0" />

关于为什么我们无法运行现有迁移有什么想法吗?

【问题讨论】:

  • 你跑dotnet ef database update了吗?

标签: c# .net entity-framework-core


【解决方案1】:

原来这个错误是因为缺少 Designer.cs 文件。由于the response in this post,我们删除了它们,但没有它们,EF 无法找到我们的迁移。如果您计划在任何其他环境中运行迁移,请不要删除您的 Designer 文件!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 2021-08-09
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2015-09-13
    相关资源
    最近更新 更多