.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项目所在文件夹执行
1 | dotnet ef --startup-project ..\web_project\ migrations add init |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?