efcore / EFCore.FSharp

Adds F# design-time support to EF Core
MIT License
228 stars 26 forks source link

No ModelSnapshot was found. #116

Closed lucasteles closed 2 years ago

lucasteles commented 2 years ago

Describe the bug

The is to things that I think are correlated.

When I run:

dotnet ef migrations add Foo
dotnet ef migrations add Bar

It generates two equal migrations, with the same code, In C# the second migration would be empty.

When I try to remove the migrations with: `dotnet ef migrations remove -ft

I get an error

Build started...
Build succeeded.
No ModelSnapshot was found.

It never creates an empty migration, I think that is because it is no finding de snapshot

To Reproduce Steps to reproduce the behavior:

  1. Create a project
  2. Add 2 migrations
  3. Try to remove one

I reproduced this issue here https://github.com/lucasteles/fsharp-efcore

Expected behavior Create empty migrations when there are no new changes. Be able to remove a Migration

simon-reynolds commented 2 years ago

Hi @lucasteles Thanks for the reproduction, I'll take a look at this when I can

simon-reynolds commented 2 years ago

Hi @lucasteles

You have to add the migrations to the fsproj below Context.fs for them to be included

<Compile Include="Context.fs" />
<Compile Include="Migrations/*.fs" />

A wildcard can be used to glob the files since they will always be created in a sorted order. Once that is done, Bar would be created as an empty migration as expected. Unfortunately, I don't have any workaround for this at the moment, the fsproj file has to be manually edited to add the migrations