EF6.3 Add-Migration is not recognized as the name of a cmdlet
See original GitHub issueUpon 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)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (4 by maintainers)
Re-opening. We should consider just adding the functions back to our
Export-ModuleMember
call.No danger. I removed them because they are redundant in newer versions of PowerShell.