Error in update-database command in code first migration

后端 未结 10 1536
盖世英雄少女心
盖世英雄少女心 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:22

    Diego's answer is correct.

    This problem occurs when there is no connection string in project marked as startup project. Then EF tries to connect to some default database engine to perform update. In my case it tried to use express, and for some reason it couldn't connect. And the error was thrown.

    Run your "update-database" with option "-Verbose". One of the lines there shows which StartUp project is used. Check your connection string in this project, or change the startup project to the one that has correct connection string. That solves the problem.

提交回复
热议问题