Error in update-database command in code first migration

后端 未结 10 1546
盖世英雄少女心
盖世英雄少女心 2020-12-15 05:01

I am working on Desktop application in WPF and creating SqlRepository with LocalDB to store data. I am using following tools

  • Visual Studio 20
10条回答
  •  无人及你
    2020-12-15 05:38

    As explained in other answers, the problem usually comes from having the wrong Initial project in Package Manager Console. In my case the console was ignoring the value I selected in the Default Project drop down list, and also the -StartUpProjectName parameter, and reproducing the wrong behavior of trying to connect to some default database engine, as Mikk's answer describes, in my case using a SqlExpress engine.

    My problem was caused by a wrong solution configuration: if your solution has several projects and is meant to be run with the configuration option "Multiple startup projects", but you just downloaded it from your source code control repository, then it is possible that the default configuration option "Single startup project" is being applied to the solution (this config value usually is not checked-in in the source code control). In this case the Package Manager Console just ignores the startup project selected in its combo and just applies the default startup project in the solution, which may not have a connection string, as specified in Mikk's answer.

    So I fixed it by changing the solution properties: Common properties / Startup project / Select Multiple startup projects instead of Single startup project, and after that the Package Manager Console would accept the Project name and update the right database.

提交回复
热议问题