问题
i'm using entity framework data migrations. if i change something about entites or something else, i try to use "add-migration MyFirstMigration" on Package Manager Console. But it returns an exception :
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 inclu
ded, verify that the path is correct and try again.
At line:1 char:14
+ add-migration <<<<
+ CategoryInfo : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
if i uninstall EntityFramework.Migrations from Nuget and re-install it's working with same code ("add-migration MyFirstMigration","update-database") till close project.
how can i fix it ? anyone else experiencing this?
EDIT : it works fine on another pc by the way...
回答1:
I ran into this also, although I am testing VS 11 and EF5, so this may not apply to you. It could be a couple of things.
You have to open VS in the following order:
- With VS open, close the package manager console
- Close VS
- Open VS
- Open your project
- Open the package manager console
If you close VS, when the package manager console is open, it remembers that. Then, when you reopen VS, the package manager console is already open before you open your project and it gets confused.
The other possibility is that you have other EF packages installed that don't know about "add-migration" and they are geting in the way.
Run "get-package" in the package manager console, to see what is installed. Remove the unnecessary/old stuff.
回答2:
Sometimes this error occur, when we copy and paste the command in default opened Package Manager Console(PMC), I also getting same error while pasting the command and trying to execute it, but when I closed the PMC and VS and again I open the VS and then PMC, after that I type the PMC command then it executed successfully.
来源:https://stackoverflow.com/questions/8678792/ef-data-migrations-does-not-work-after-close-project