问题描述
最近从EF Core 1.0迁移到EF Core 2.0,并且运行良好。今天,我添加了一个新表(代码优先),并将其添加到我的DbContext中:
Recently migrated from EF Core 1.0 to EF Core 2.0, and it runs fine. Today I added a new table (code-first) and added it to my DbContext with:
public virtual DbSet<Foo> Foos { get; set; }
当我运行迁移时,将我的DbContext放在一个单独的项目中(请记住,在之前),迁移结束,但未创建迁移文件。这一切在Core 2.0之前都可以使用,
When I run a migration, with my DbContext in a separate project (remember this was all working before), the migration ends, but no migration files were created. This was all working prior to Core 2.0 using:
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,开始清理工作,但仍然没有工作。
No errors that seem obvious to me, and no migration files created. I've done a Remove-Migration to start clean, but still no workie.
推荐答案
我必须将一个项目标记为启动项目。
I had to mark a project as the start-up project.
这篇关于Entity Framework Core 2.0 Add-Migration不会创建任何迁移文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!