Ef6: EF6.3 Add-Migration is not recognized as the name of a cmdlet

Created on 3 Oct 2019  路  10Comments  路  Source: dotnet/ef6

Upon installing EF6.3 (to get this fix; thanks for that fix!), I tried to add a migration. I instantly ran into this error:

PM> Add-Migration
Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if 
a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Add-Migration
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Steps to reproduce

I typed in Add-Migration (or any EF migration command) into the Package Manager Console.
This is using the Package Manager Console after upgrading to 6.3 from 6.2. In my attempt to fix the issue, I:

  • restarted Visual Studio
  • used multiple machines
  • updated from VS17 15.6.9 to 15.6.16
  • deleted entityframework folders from my .nuget packages folder
  • do a nuget Update-Package EntityFramework -reinstall command.
  • Did multiple import-module commands:
PM> Remove-Module EntityFramework6 -verbose -force
Performing the operation "Remove-Module" on target "EntityFramework6 (Path: 'C:\Users\jhaug\.nuget\packages\entityframework\6.3.0\tools\EntityFramework6.psm1')".
Removing the imported "InitialDatabase" variable.

PM> Import-Module C:\Users\jhaug\.nuget\packages\entityframework\6.3.0\tools\EntityFramework6.psd1 -verbose -force
Loading module from path 'C:\Users\jhaug\.nuget\packages\entityframework\6.3.0\tools\EntityFramework6.psd1'.
Loading module from path 'C:\Users\jhaug\.nuget\packages\entityframework\6.3.0\tools\EntityFramework6.psm1'.
Importing variable 'InitialDatabase'.

PM> (Get-Module -Name EntityFramework6)

ModuleType Version    Name                                ExportedCommands                                                                                            
---------- -------    ----                                ----------------                                                                                            
Script     6.3.0      EntityFramework6   

Personal Fix

I ended up fixing the issue by changing a line in EntityFramework6.psm1:

I modified:

Export-ModuleMember -Variable 'InitialDatabase'

and changed it to (based off of 6.2's version):

Export-ModuleMember @( 'Enable-Migrations', 'Add-Migration', 'Update-Database', 'Get-Migrations', 'Add-EFProvider', 'Add-EFDefaultConnectionFactory', 'Initialize-EFConfiguration') -Variable InitialDatabase

I don't know if the above fix I applied is recommended, but I discovered modifying that line is the only thing I tried that fixed this issue. After applying this change, I could call Add-Migration on my project without issue.

Further technical details

EF version: 6.3.0
Database Provider: (e.g. EntityFramework.SqlServer)
Operating system: Windows 8.1 Pro
IDE: Visual Studio Community 2017 Version 15.6.16 (also was on 15.6.9 before)

closed-fixed regression type-bug

Most helpful comment

Re-opening. We should consider just adding the functions back to our Export-ModuleMember call.

All 10 comments

Weird. What's the output of $PSVersionTable?

I can't seem to reproduce this problem. I have a solution with one ASP.Net MVC 5 web app and a couple of libraries. All used EF6.2, upgrade to 6.3 went fine. I've even added migrations afterward as well. The only difference I can see is VS version. Mine is VS2019 Professional, 16.3.2
Projects are targeting .NET 4.7 but that shouldn't matter.

This might be related to #1348

Same thing for me, after upgrading to 6.3.0 (.NET Framework 4.8)

Error:

PM> Update-Database
Update-Database : The term 'Update-Database' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
At line:1 char:1
+ Update-Database
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Update-Database:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Tried this workaround from here
PM> Import-Module .\packages\EntityFramework.6.3.0\tools\EntityFramework6.psd1
with same results.


More details:

  • Project type: ClassLibrary | .NET Framework 4.8
  • IDE: Visual Studio 2019 Community (16.3.4)
  • Dependency using package.config: <package id="EntityFramework" version="6.3.0" targetFramework="net48" />

"Solved" by:
Going back to EF 6.2.0

Uninstall-Package EntityFramework -Verbose -ProjectName <Your_Project>
Install-Package EntityFramework -Version 6.2.0 -Verbose -ProjectName <Your_Project>
Update-Database -StartUpProjectName <Your_Project>

After that the Update-Database command works again.

Got this some days ago! Manually applying the change in https://github.com/aspnet/EntityFramework6/pull/1300 seems to fix it.

Downgrading to 6.2 is not an option for me.

@ajcvickers I also have this issue on my 2012 R2 server machine ( No exported commands ).

PM> import-module C:\Users\Administrator\.nuget\packages\entityframework\6.3.0\tools\entityframework6.psm1
PM> Get-Module -name entityframework6

ModuleType Version    Name                                ExportedCommands                                                                                                         
---------- -------    ----                                ----------------                                                                                                         
Script     6.3.0      EntityFramework6                                                                                                                                             

I cannot determine which issue this is a duplicate of. I have also tried the fix in 6.4.

Modifying ..\tools\entityframework6.psm1 with:

Export-ModuleMember @( 'Enable-Migrations', 'Add-Migration', 'Update-Database', 'Get-Migrations', 'Add-EFProvider', 'Add-EFDefaultConnectionFactory', 'Initialize-EFConfiguration') -Variable InitialDatabase

Is the only fix that worked for me.

Re-opening. We should consider just adding the functions back to our Export-ModuleMember call.

@bricelam And danger in doing this for 6.4? If not, I say let's do it.

No danger. I removed them because they are redundant in newer versions of PowerShell.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AnReZa picture AnReZa  路  4Comments

steamwings picture steamwings  路  7Comments

Elufimov picture Elufimov  路  7Comments

FransBouma picture FransBouma  路  7Comments

narendrasinghrathore picture narendrasinghrathore  路  5Comments