EF Core "no migrations found" despite Migrations folder containing migration files

.net c# entity-framework-core


We have a .NET Core project set up with a Migrations folder containing several migrations that we were able to successfully run in our Development database in the past by executing dotnet ef database update. However, we are now trying to apply those changes to our Staging database and it isn't working. We've set our ASPNETCORE_ENVIRONMENT env variable to Staging and when we attempt to run the migrations, it seems like it is targeting Staging properly. A dbo.__EFMigrationsHistory table is created in our Staging database, but there are no entries in it. Also, when we run dotnet ef migrations list, we get a message that says "No migrations were found." Even if we set the ASPNETCORE_ENVIRONMENT variable back to Development, we get the same result.

We've run all the above dotnet ef commands with the verbose flag and haven't gotten any errors. The only output that seems like it could be suspicious is No referenced design-time services were found and No design-time services were found, but we weren't able to determine what we need to do to fix these issues.

When we run dotnet ef migrations add <migration name>, it successfully generates a migration file in the Migrations folder, and when we run dotnet ef migrations list that new migration shows up, so it seems like our older migrations are in the correct place. They just aren't being detected by dotnet ef for some reason.

We have the following packages in our .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>
    <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>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0" />

Any thoughts on why we can't get our existing migrations to run?

2/25/2020 3:22:46 PM

Accepted Answer

It turns out this error was because of the lack of Designer.cs files. We deleted them due to the response in this post, but EF was not able to find our migrations without them. If you plan on running your migrations in any other environments, don't delete your Designer files!

2/28/2020 6:08:30 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow