add-migration System.ArgumentNullException: Value cannot be null. Parameter name: key
See original GitHub issueExecuting add-migration, I am getting System.ArgumentNullExceptionL Value cannot be null. Parameter name: key.
I got this after updating VS2017 and installing SDK 2.1.300.
My guess is that there is something amiss in my model somewhere, but would like verification that that would be a good guess, given this exception, or if it’s likely to be something else. Also wondering if anyone has any hints of how to track down the source, since there are no line numbers in the stack trace and none of it references any of my solution’s classes.
Here’s the exception and stack trace:
System.ArgumentNullException: Value cannot be null.
Parameter name: key
at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.EntityFrameworkCore.RelationalMetadataExtensions.Relational(IKey key)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<Add>d__35.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__34`1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<Add>d__26.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<DiffCollection>d__50`1.MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IModel source, IModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace)
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_1.<.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)
Further technical details
EF Core version: 2.0.3 Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL Operating system: Windows Server 2008 R2 IDE: Visual Studio 2017 15.7.3
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:16 (5 by maintainers)
Top Results From Across the Web
Add-Migration Value cannot be null. Parameter name
I'm using EF Core 2.2.4, i'm trying to rollback a migration with: ... System.ArgumentNullException: Value cannot be null. Parameter name: ...
Read more >EF Code First Migrations failure in VS 2022 v17.0.0 P1 #1870
All three of these commands return the following error... System.ArgumentNullException: Value cannot be null. Parameter name: type at System.
Read more >Entity Framework : Value cannot be null. Parameter name: type
entity-framework: Entity Framework : Value cannot be null. Parameter name : type Thanks for taking the time to learn more.
Read more >[Solved]-Add-Migration Value cannot be null. Parameter name
I'm using EF Core 2.2.4, i'm trying to rollback a migration with: ... System.ArgumentNullException: Value cannot be null. Parameter name: name.
Read more >Value cannot be null. [SOLVED] - Complete Process - YouTube
[SOLVED] System. ArgumentNullException : Value cannot be ... System. ArgumentNullException : Value cannot be null. ... Parameter name : entity'.
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
I just found the problem… turns out I was giving it a null value 🤦♂️
Even with non-nullables, sometimes things sneak through, especially when you select entire entities.
The lesson here is probably always to query for individual fields… which, actually, is kind of hard when you want to query for entities by reference rather than by ID.
@reinux I did not get a solution to this at that time (I hope it was fixed in a later patch by EF Team) and I rather moved to SSDT for applying database changes as it is more reliable and can be applied to SQL database out of any order, i.e. If I want I can merge any SQL object change in my release branch from dev branch and simply ask it to apply changes. The SSDT runtime automatically generates difference scripts. And at this point if you need to update data, you can do it via Pre-deployment or Post-deployment scripts. If you use EF Migrations, them post merging desired changes, you have to create a new migration in Release branch! Further if your DBA did some changes on DB directly, then these migrations may fail!!
By the way, if you are still on these versions then you are already out of support, so better go to the latest LTS version now.