How to Fix Both Entity Framework Core and Entity Framework 6 Build Failed ASP.NET Core MVC

In the new ASP.NET Core MVC, the framework uses Entity Framework Core instead of Entity Framework 6. Typically if you start a new project using .NET Core you will only have one version of the Entity Framework. But if you are upgrading or adding a new project alongside classic MVC ASP.NET, then the previous version of Entity Framework is installed alongside Core. In my case, it is Entity Framework 6.

If this is the case, the old command of “Add-Migration” for creating your Code-First Migration is going to give you an error similar to below:

Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use ‘EntityFramework\Add-Migration’ for Entity Framework 6.
Build failed.DotNet Core EF Migration Add-Migration

You can go to the trouble of installing the old version of Entity Framework and that should fix the problem. However a quick workaround is to use the new commands for .NET Core — dotnet ef migrations add “InitialDBCreate” –project “MiloRiano.WebApp” -c MiloWebAppDbContext.

The command below simply uses “dotnet ef migrations add”, followed by the name of the migration and the targeted project (“–project”) in my case MiloRiano.WebApp, and the context (“-c”) ¬†used, MiloWebAppDbContext.

This should solve your problem and have an output similar to below:

dotnet ef migrations add “InitialDBCreate” –project “MiloRiano.WebApp” -c MiloWebAppDbContext
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.2.4-servicing-10062 initialized ‘MiloWebAppDbContext’ using provider ‘Microsoft.EntityFrameworkCore.SqlServer’ with options: None
Done. To undo this action, use ‘ef migrations remove’

Hope this works for you.

Leave a Reply

Your email address will not be published.

Previous Story

Error Visual Studio Scrapy No Module Named Win32API

Latest from Programming