美文网首页
More than one DbContext was foun

More than one DbContext was foun

作者: 海玲珑 | 来源:发表于2018-04-23 15:22 被阅读0次

调用多个数据库时用户命令执行操作报错

环境

win7x64、VS2017、Asp.Net Core 2.0

错误:

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

111.png
  • 执行的命令是:dotnet ef migrations add NewDatabase

原因

由于使用的多个DbContext,而在使用命令生成数据库文件时又没有指定是执行哪个DbContext

解决办法:

(使用命令是指定是在哪个数据库执行)
如在原命令后加上代码-c DbContext的文件名,如下

  • 执行命令生成创建的文件
    dotnet ef migrations add Initial -c DemoDbContext
  • 执行命令生成数据库
    dotnet ef database update -c DemoDbContext

相关文章

网友评论

      本文标题:More than one DbContext was foun

      本文链接:https://www.haomeiwen.com/subject/gulllftx.html