.net 6 ef code first迁移报错解决,"Unable to create an object of type 'MyDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728"

数据访问层添加nuget包:

Microsoft.EntityFrameworkCore

Npgsql.EntityFrameworkCore.PostgreSQL

Microsoft.EntityFrameworkCore.Tools

 

使用dotnet ef命令迁移报错,就很纳闷,"Unable to create an object of type 'MyDbContext'. For the different patterns supported at design time"

使用vs的程序包管理器迁移也是同样的错误。

然后把启动项改为web项目,提示缺少"Microsoft.EntityFrameworkCore.Design"包,遂安装上,然后执行成功。

 

总结(省流量):web项目需要安装或者引用的项目有Microsoft.EntityFrameworkCore.Design包。如果使用dotnet ef命令,在data项目所在文件夹执行

dotnet ef --startup-project ..\web_project\ migrations add init

 

posted @ 2022-07-23 20:24  小辫子啦啦啦  阅读(4485)  评论(1编辑  收藏  举报