EF Data Migrations does not work after close project

天涯浪子 提交于 2019-12-23 12:40:25

问题


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:

  1. With VS open, close the package manager console
  2. Close VS
  3. Open VS
  4. Open your project
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!