Is there anyway to debug Add-Migrations?
See original GitHub issueI refactor my code to inherit my entities from an abstract generic type.
If I Add-Migrations from Existing migrations it give me error.
But, If I delete all previous Migrations and run Add-Migrations. It will create a new successful migration file.
The error is the following:
System.ArgumentException: An item with the same key has already been added. Key: System.Object Item [System.String]
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetSortedProperties(IEntityType entityType, ITable table)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetSortedColumns(ITable table)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Add(ITable target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+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(IRelationalModel source, IRelationalModel target)
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, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
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)
Is there anyway to debug the Add-Migrations process? because the error message with “Key: System.Object Item [System.String]” is not helpful. I cannot know which part of my code might have conflicted key.
EF Core version: Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: (e.g. .NET 6.0) Operating system: IDE: (e.g. Visual Studio 2022 17.3.4)
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
EF Core Add Migration Debugging
I've seen lots of posts on how to debug the actual migration, but nothing on how to watch how the model code is...
Read more >Debugging Entity Framework Core migration scaffolding and ...
Debugging migration application. Let's start with the easier part - debugging the situation when errors appear while changes to the database ...
Read more >Debugging your Entity Framework Migration Seeding
Leave the debugger (Second instance of Visual Studio) open between runs. You can start and stop the first instance at will. Your breakpoints ......
Read more >Debugging Your AWS DMS Migrations: What to Do When ...
This post gives you a quick introduction to the initial steps that you need to take to debug AWS DMS migrations. It also...
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 add
if (!Debugger.IsAttached) Debugger.Launch();
in my IDesignTimeDbContextFactory so I only have to attach a debugger when working with the migrations. But any other point that runs before it’s configuring the model (like ConfigureServices or in OnConfiguring as the first line or just the constructor of the dbContext will enable you to attach the debugger.Here’s a snippet I sometimes use to add a migration from a console program, in order to debug issues: