问题一:Add-Migration 时出现 此类问题一般都是模型类主键标识问题增加KEY即可解决
报错:
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 相关包,需引用包
报错:
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.
以上问题方案: