Using Entity Framework for UWP app sqlite. All is fine, but wanted to add migrations for future updates.
Following steps here: https://stackoverflow.com/a/68759414/9068892
I was able to add a single migration, which does in fact create a Migrations folder with a migration and a SVContextModelSnapshot.cs file. Everything seems fine.
Now if I make a change (or don't) and then run Add-Migration Test
, it creates a new migration but as if there was no per-existing state. It does a CreateTable for every model and remakes the whole database from scratch. This is obviously wrong I'd expect to just see my single column added. Adding a -verbose tag doesn't show anything surprising.
Doing a "Remove-Migraiton" gives me a hint of something a miss, as it gives the error
No ModelSnapshot was found.
Looking at Remove-Mgiraiton -verbose
and Add-Migration Test -Verbose
, all the paths look perfectly fine. The snap shot file is right there. It just doesn't seem to be used.
Remove-Migration -verbose
Using project 'Data'.
Using startup project 'MigrationProj'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0\MigrationProj.deps.json --additionalprobingpath C:\Users\SomeUser\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files (x86)\Microsoft\Xamarin\NuGet" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0\MigrationProj.runtimeconfig.json C:\Users\SomeUser\.nuget\packages\microsoft.entityframeworkcore.tools\3.1.25\tools\netcoreapp2.0\any\ef.dll migrations remove --json --verbose --no-color --prefix-output --assembly C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0\Data.dll --startup-assembly C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0\MigrationProj.dll --project-dir C:\dev\Sample\UWPApp\Data\ --language C# --working-dir C:\dev\Sample\UWPApp --root-namespace Data
Using assembly 'Data'.
Using startup assembly 'MigrationProj'.
Using application base 'C:\dev\Sample\UWPApp\MigrationProj\bin\Debug\net6.0'.
Using working directory 'C:\dev\Sample\UWPApp\MigrationProj'.
Using root namespace 'Data'.
Using project directory 'C:\dev\Sample\UWPApp\Data\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding Microsoft.Extensions.Hosting service provider...
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'SVContext'.
Using context 'SVContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.Sqlite'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.Sqlite'.
Finding design-time services referenced by assembly 'MigrationProj'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'MigrationProj'...
No design-time services were found.
'SVContext' disposed.
Microsoft.EntityFrameworkCore.Design.OperationException: No ModelSnapshot was found.
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
No ModelSnapshot was found.
CodePudding user response:
Problem was solved by deleting the ".vs" folder and restarting VS.