5

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 ??

6
  • EntityFrameworkCore\Add-Migration anything?
    – Ivan Stoev
    Aug 3, 2018 at 13:24
  • 1
    You can try with dotnet core cli tools . You should be able to run migrations from external command window by pointing to project folder...
    – Nish26
    Aug 3, 2018 at 13:52
  • 1
    you could try dotnet ef add-migration if you get an error saying dotnet-ef isn't a command, then you're missing the tooling from your .CSPROJ file. Aug 3, 2018 at 15:54
  • @AdamVincent I had exactly the same error 'dotnet-ef isn't a command' , but adding tools its throwing error : ''DotnetCliTool' is not supported by project' . Aug 4, 2018 at 7:55
  • are you targeting a .net core app? You can use EF 6 in a .NET Core App, but you can't use EF Core in a .NET Framework app afaik Aug 4, 2018 at 19:15

2 Answers 2

10

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

3
  • 1
    plus one for Get-Modules but when I remove EntityFramework6 and reopen visual studio it get back to the list
    – sabsab
    Apr 17, 2022 at 21:27
  • 1
    thanks to your answer . but when I reopen my vs I see this again . exactly like @sabsab May 29, 2022 at 7:03
  • @HaydarDehghan I solved the problem... it was a nuget package that refrerences old ef 6
    – sabsab
    May 29, 2022 at 18:26
7

For EF6:

EntityFramework\Add-Migration <MIGRATIONNAME>

For EF Core:

EntityFrameworkCore\Add-Migration <MIGRATIONNAME>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.