dotnet ef migrations add throws exception
See original GitHub issueI have a ASP.NET Core 3 project with database context using EF Core 3 and SQL Server. When I add a new migration, it fails with NullReferenceException error.
Steps to reproduce
dotnet ef migrations add UpdateDatabase1 -c ApplicationDbContext
Verbose log: https://gist.github.com/jozefizso/b932c31b5b78f3558468ea605aadb505
Exception reported to console:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.OnAnnotationSet(String name, IConventionAnnotation annotation, IConventionAnnotation oldAnnotation)
at Microsoft.EntityFrameworkCore.Metadata.Internal.ConventionAnnotatable.OnAnnotationSet(String name, Annotation annotation, Annotation oldAnnotation)
at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.RemoveAnnotation(String name)
at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.Microsoft.EntityFrameworkCore.Metadata.IMutableAnnotatable.RemoveAnnotation(String name)
at Microsoft.EntityFrameworkCore.Migrations.Internal.SnapshotModelProcessor.ProcessElement(IAnnotatable metadata, String version)
at Microsoft.EntityFrameworkCore.Migrations.Internal.SnapshotModelProcessor.ProcessElement(IEntityType entityType, String version)
at Microsoft.EntityFrameworkCore.Migrations.Internal.SnapshotModelProcessor.Process(IModel model)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>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)
Object reference not set to an instance of an object.
Further technical details
EF Core version: 3.0.0 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET Core 3.0 Operating system: Windows 10 IDE: Visual Studio 2019 16.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
dotnet ef migrations add throws exception
and got the exception "Index was outside the bounds of the array." User-MacBook-Pro WebAPITutorial % dotnet ef migrations add Student --project ...
Read more >Got the Exception when ef migration add/remove on .NET ...
I use the ASP .Net Core 6(6.0.7) with minimal API. And when I use the ef migrations Add ..., I get the exceptions...
Read more >Error while Add-Migration "Initialize" in .NET 6 Entity ...
It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '2.0.0' (x64) was not found.
Read more >dotnet ef migrations add throws exception-Entity Framework
Can't add EF 6.4 migrations in a .Net Standard 2.1 project · Entity Framework Power Tools Beta 3 throws exception "sequence contains no...
Read more >Breaking changes in EF Core 7.0 (EF7)
Complete list of breaking changes introduced in Entity Framework Core 7.0 ... Some warnings will again throw exceptions by default, High.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, this worked for me.
Had to change the version in the ApplicationDbContextModelSnapshot
modelBuilder .HasAnnotation("ProductVersion", "3.0.0")
This was for a project which was previously in EF Core 1.1.5 version to EF Core 3.0.0
Ran into same issue when trying to add a migration. Any update on this?