Great question! These are exactly the kinds of migration issues that trip up developers during .NET version upgrades. Here's a consolidated answer covering all four bugs with complete fixes and some additional tips from real-world experience.
Fix #1 — EF Tools vs runtime version mismatch
Always keep your Tools and Design packages on the same major version as your runtime. Run these in your startup project:
dotnet add package Microsoft.EntityFrameworkCore.Tools --version 10.0.0
dotnet add package Microsoft.EntityFrameworkCore.Design --version 10.0.0
Pro tip: When upgrading EF Core, treat Tools, Design, and the core runtime packages as a single upgrade unit — never upgrade one without the others.
Fix #2 — Missing Design package
The Design package must be in your startup project, not just your infrastructure/data project. In your startup project's .csproj:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design"
Version="10.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
The PrivateAssets=all flag ensures it's a dev-only dependency and won't be published to production.
Fix #3 — Migration assembly mismatch (multi-project solutions)
Always specify both --project (where migrations live) and --startup-project (your API/web project) explicitly:
dotnet ef migrations add InitialCreate \
--project src/MyApp.Infrastructure \
--startup-project src/MyApp.Api
Also make sure your DbContext registration includes the migrations assembly:
options.UseSqlServer(connectionString, x =>
x.MigrationsAssembly("MyApp.Infrastructure"));
Fix #4 — Safely removing a bad migration
Never manually delete migration files. Always follow this safe sequence:
Step 1: Roll back the database first
Update-Database -TargetMigration LastGoodMigration
Step 2: Then remove the bad migration file safely
dotnet ef migrations remove
If you already deleted the file manually, query __EFMigrationsHistory to find the last applied migration, then run Update-Database to that target to resync.
Bonus tip — never run migrations auto-apply in production
Avoid context.Database.Migrate() in your startup pipeline for production environments. Generate a SQL script instead and review it before applying: dotnet ef migrations script --idempotent
Quick reference checklist
Tools, Design, and runtime on same major version
Design package in startup project with PrivateAssets=all
Always use --project and --startup-project flags in multi-project solutions
Roll back DB before removing migration files — never delete manually
Use --idempotent SQL scripts for production deployments