question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bricelamcommented, Oct 21, 2019

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

0reactions
bricelamcommented, Oct 21, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

The term "Add-Migration" is not recognized
1) Open project.json file and Remove all Microsoft.EntityFrameworkCore. · 2) Close Package Manager Console (PMC) and restart Visual Studio · 3) ...
Read more >
The term 'Add-Migration' is not recognized as the name of a ...
Getting an error :Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program ......
Read more >
The Term 'Add-Migration' Is Not Recognized
Sometimes, the error persists because of cache, so restarting your visual studio can solve the issue without doing anything. ASP.NET · ASP.NET ...
Read more >
The term 'add-migration' is not recognized as the ... - YouTube
If you get this type of error during migration like add-migration migration_name is not recognized as the name of cmdlet.
Read more >
add-migration : The term 'add-migration' is not recognized…
add-migration : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found