More than one DbContext was found. Specify which one to use. Use the '-Context'

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

环境

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。