EF data migration does not work after project closure

I am using entity structure data migration. if I changed something about entites or something else, I'm trying to use "Add-migration MyFirstMigration" in the 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 remove EntityFramework.Migrations from Nuget and reinstall it, working with the same code ("add-migration MyFirstMigration", "update-database") before closing the project.

how can i fix this? Does anyone else experience this?

EDIT: It works fine on another PC, by the way ...

+4
source share
2 answers

I came across this as well, although I am testing VS 11 and EF5, so this may not apply to you. This may be a few things.

You need to open VS in the following order:

  • When VS is open, close the package manager console
  • Close VS
  • Open VS
  • Open project
  • Open the package manager console

If you close VS when the package manager console is open, it remembers that. Then, when you open VS again, the package manager console is already open before you open your project and get confused.


Another possibility is that you have other EF packages installed that do not know about add-migration, and they interfere.

Run "get-package" in the package manager console to find out what is installed. Remove unnecessary / old things.

+12
source

Sometimes this error occurs when we copy and paste the command into the open package manager console by default (PMC), I also get the same error when pasting the command and trying to execute it, but when I close PMC and VS and again I open VS and then PMC, after which I type the PMC command, after which it runs successfully.

0
source

Source: https://habr.com/ru/post/1388588/


All Articles