返回

vs 2019 社区版 .net core 5.0 之 .net core ef 迁移问题方案

发布时间:2022-10-24 21:24:36 297

问题一:Add-Migration 时出现 此类问题一般都是模型类主键标识问题增加KEY即可解决

报错:

vs 2019 社区版 .net core 5.0 之  .net core ef 迁移问题方案_主键

​The entity type 'xxxx' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943.​

以上问题方案
​​​ public class XXXX { **[Key]** public int UserID { get; set; }//用户识别ID 主键 public string UserNike { get; set; } }​

问题二:
Add-Migration 时出现这类问题(我是因为我选了默认项目模型类)) 一般情况下是当前默认项目(可以切到需要生成的项目下)中缺少entity framework core 相关包,需引用包

报错:

vs 2019 社区版 .net core 5.0 之  .net core ef 迁移问题方案_主键_02

​Your target project '解决方案名' doesn't match your migrations assembly '默认项目'. Either change your target project or change your migrations assembly. Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("WebBlogFirst")). By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.​以上问题方案

Add-Migration 时出现这类问题(我是因为我选了默认项目模型类)) 一般情况下是当前默认项目(可以切到需要生成的项目下)中缺少entity framework core 相关包,需引用包**

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线
下一篇
Java study 4 2022-10-24 20:30:53