Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF6.3 Add-Migration is not recognized as the name of a cmdlet #1337

Closed
ThunderSizzle opened this issue Oct 3, 2019 · 10 comments · Fixed by #1414
Closed

EF6.3 Add-Migration is not recognized as the name of a cmdlet #1337

ThunderSizzle opened this issue Oct 3, 2019 · 10 comments · Fixed by #1414

Comments

@ThunderSizzle
Copy link

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)

@bricelam
Copy link
Contributor

bricelam commented Oct 3, 2019

Weird. What's the output of $PSVersionTable?

@hayer
Copy link

hayer commented Oct 4, 2019

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.

@xantari
Copy link

xantari commented Oct 5, 2019

This might be related to #1348

@lsolano
Copy link

lsolano commented Oct 10, 2019

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.

@hayer
Copy link

hayer commented Oct 14, 2019

Got this some days ago! Manually applying the change in #1300 seems to fix it.

Downgrading to 6.2 is not an option for me.

@ToddThomson
Copy link

@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.

@ToddThomson
Copy link

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.

@bricelam
Copy link
Contributor

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

@ajcvickers
Copy link
Contributor

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

@bricelam
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants