c# - Entity Framework Core 2.0 Add-Migration 不创建任何迁移文件

标签 c# entity-framework database-migration entity-framework-migrations entity-framework-core

最近从 EF Core 1.0 迁移到 EF Core 2.0,并且运行良好。今天我添加了一个新表(代码优先)并将其添加到我的 DbContext 中:

public virtual DbSet<Foo> Foos { get; set; }

当我运行迁移时,我的 DbContext 在一个单独的项目中(记住这一切之前都是有效的),迁移结束,但没有创建迁移文件。这一切都在 Core 2.0 之前使用:

http://paultechguy.blogspot.com/2017/04/entity-framework-core-migrating-and.html

PM> Add-Migration GradePremade -project Mfc.MfcRepositoryModel -verbose -context MfcDbContext -StartupProject web.xyz
Using project 'class.xyz\Mfc.MfcRepositoryModel'.
Using startup project 'web.xyz'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0\web.xyz.deps.json --additionalprobingpath C:\Users\pcarver\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0\web.xyz.runtimeconfig.json "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.0.0\tools\netcoreapp2.0\ef.dll" migrations add GradePremade --json --context MfcDbContext --verbose --no-color --prefix-output --assembly C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0\Mfc.MfcRepositoryModel.dll --startup-assembly C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0\web.xyz.dll --project-dir C:\development\xyz\class.xyz\Mfc.MfcRepositoryModel --root-namespace Mfc.MfcRepositoryModel
Using assembly 'Mfc.MfcRepositoryModel'.
Using startup assembly 'web.xyz'.
Using application base 'C:\development\xyz\web.xyz\bin\Debug\netcoreapp2.0'.
Using working directory 'C:\development\xyz\web.xyz'.
Using root namespace 'Mfc.MfcRepositoryModel'.
Using project directory 'C:\development\xyz\class.xyz\Mfc.MfcRepositoryModel'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding BuildWebHost method...
No BuildWebHost method was found on type 'xyz.Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'ApplicationDbContext'.
Found DbContext 'MfcDbContext'.
Using DbContext factory 'MfcContextFactory'.
Using context 'MfcDbContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'web.xyz'...
No design-time services were found.

没有对我来说很明显的错误,也没有创建迁移文件。我已经完成了 Remove-Migration 以开始清理,但仍然没有工作。

最佳答案

.NET Core 类库中存在问题。成功的解决方法是将以下内容放入 Model 项目的 csproj 文件中:

<PropertyGroup>
  <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> 
</PropertyGroup>

关于c# - Entity Framework Core 2.0 Add-Migration 不创建任何迁移文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45851229/

相关文章:

mysql - 在 GCP 帐户之间迁移 MySQL 数据库的最佳方法是什么?

grails - 启动后如何运行Grails数据库迁移

javascript - imageButton 的服务器标记格式不正确

c# - 处理 15000 个工作项的最佳方式,每个工作项需要 1-2 次 I/O 调用

c# - Entity Framework + LINQ + "Contains"== 超慢?

c# - 在不同的程序集上分布 Entity Framework 模型

database - 无法使 Goose DB Migration 用于 Go 测试

c# - 不移动光标修改文本框

c# - 方法重载

entity-framework - Entity Framework 代码第一个问题无法确定类型之间关联的主体