I am working on a .NET Core 2.2 project. And I installed the Entity Framework Core nuget package.
But when I try to enable migrations, got error
The EntityFramework package is not installed on project
I found one solution for that,
One possibility for this error - In the Package Manager Console, there is a dropdown for 'Default Project'. If this is set incorrectly, you will get The EntityFramework package is not installed on project 'x'. Change the dropdown to your EF project and all is good again.
But the selected project is correct.
So I checked the module in package manager console with command,
PM> Get-Module EntityFramework*
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 6.0.0.0 EntityFramework {Add-EFDefaultConnectionFactory, Add-
EFProvider, Add-Migration...
Script 2.2.6 EntityFrameworkCore {Add-Migration, Drop-Database, Enable-
Migrations, Get-DbContex...*
So I think there are two Entity Framework versions found in my class library. But when I checked in manage nuget package option, there is Entity Framework not found , only Entity Framework Core is present.
How to solve this issue?
If your DbContext
is in a different, bespoke class library and not in your startup project, chances are you need to specify this project in your EF commands:
With powershell that would be
Add-migration NameOfMigration -Project Namespace.ToContextProject
And with the dotnet cli
dotnet ef migrations add NameOfMigration --project relativePath/ToContextProject
dotnet ef migrations add InitialCreate -p relativePath/ToContextProject
I had a similar issue where upon running Get-Module EntityFramework* I had 2 references, 1 for EntiryFramework 6.0 and the second on EntityFrameworkCore.
I never installed EntityFramework6. To get past this, however, I had to qualify the framework that I wanted to add the migration through as well as update the database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.