Shahrukh Ahmad
Shahrukh Ahmad

Reputation: 153

Add migration - Both Entity Framework Core and Entity Framework 6 are installed

I have a solution with multiple projects one of them with EF 6 and another one with entityframeworkcore.

The migrations were working fine before adding EF6 project, but now I can't use the migration's command : add-migration 'anything'

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.

For the project with EF6 I can add a migration using this way: EntityFramework\Add-Migration 'anthing_here', but I can't add a migrations to the project with EFCore using this way.

Any suggestions ??

Upvotes: 6

Views: 29548

Answers (2)

Kadaj
Kadaj

Reputation: 695

I had this same scenario happen on our project that spans now ~20 years in history.

It has everything from Web Forms, to latest .Net Core technologies. Depending on luck, I would sometimes get that PackageManagerConsole was using EFCore sometimes EF6.

I was not happy that I had to use prefixes like above answer stated so I dug deeper.

If you run command Get-Module in your PM> PackageManagerConsole you should get list of active modules:

ModuleType Version    Name                                ExportedCommands                                                                                                                                                                                                
---------- -------    ----                                ----------------                                                                                                                                                                                                
Script     6.4.4      EntityFramework6                    {Add-EFDefaultConnectionFactory, Add-EFProvider, Add-Migration, Enable-Migrations...}                                                                                                                           
Script     5.0.10     EntityFrameworkCore                 {Add-Migration, Drop-Database, Enable-Migrations, Get-DbContext...}                                                                                                                                             
Script     2.0.0.0    NuGet                               {Add-BindingRedirect, Find-Package, Get-Package, Get-Project...}                                                                                                                                                
Script     0.0        profile             

Problem here is as you can see and probably even know that both EntityFramework Core and 6 are being used by solution.

You can remove one of the modules that are conflicting, using command:

PM> Remove-Module <module-name-from-list>

What I needed was to use only EFCore so I removed EF6 module like so:

PM> Remove-Module EntityFramework6

And then you can use commands without prefixes, e.g.:

PM> Add-Migration TestMigration

Relevant discussion I had with EF team: https://github.com/dotnet/efcore/issues/27051

Upvotes: 11

ZENNON
ZENNON

Reputation: 134

For EF6:

EntityFramework\Add-Migration <MIGRATIONNAME>

For EF Core:

EntityFrameworkCore\Add-Migration <MIGRATIONNAME>

Upvotes: 7

Related Questions