Document

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

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

1、多个DbContext 时报错:

报错:

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.

解决办法:

dotnet ef migrations add initail -c PermissionDbContext

成功之后

dotnet ef database update -c PermissionDbContext

2、如果 DbContext 在另一个 DLL 中时报错:

解决办法:

services.AddDbContext<PermissionDbContext>(options =>
options.UseSqlServer(configuration.GetConnectionString("PermissionConnection"), b => b.MigrationsAssembly(assemblyName)));

其中 assemblyName 是主DLL 名称的字符串常量。(不知道为什么,它不能为变量 AppDomain.CurrentDomain.FriendlyName)。

 

 

dotnet core version: 3.1

输入

dotnet ef migrations add InitialCreate

会出现下图错误

从 3.0 起,EF Core 命令列工具 (dotnet ef) 不在 .NET Core SDK 里面,需另装。命令如下:

dotnet tool install --global dotnet-ef

 

生成 SQL 脚本命令:

dotnet ef migrations script -i -o ./migrations/dbsql.sql

这会生成 dbsql.sql 脚本,可用于手动修改数据库用。

posted @ 2020-09-23 14:47  从未被超越  阅读(402)  评论(0编辑  收藏  举报