有人能解释一下为什么我得到这个错误吗
语句与FOREIGN KEY约束"FK_ArticleTag_Tags_ArticleId"冲突.冲突发生在数据库"Blog",表"dbo. tags",列"TagId"中
public class Article
{
public Article()
{
Comments = new HashSet<Comment>();
Tags = new HashSet<Tag>();
}
[Key]
public int ArticleId { get; set; }
public int? CategoryId { get; set; }
[StringLength(30)]
public string ArticleName { get; set; } = null!;
public string? ArticleDescription { get; set; }
public bool Visibility { get; set; }
[ForeignKey("CategoryId")]
[InverseProperty("Articles")]
public virtual Category Category { get; set; }
[InverseProperty("Article")]
public virtual ICollection<Comment> Comments { get; set; }
[ForeignKey("TagId")]
[InverseProperty("Articles")]
public virtual ICollection<Tag> Tags { get; set; }
}
public class Tag
{
public Tag()
{
Articles = new HashSet<Article>();
}
[Key]
public int TagId { get; set; }
[Required]
[StringLength(50)]
public string Title { get; set; }
[ForeignKey("ArticleId")]
[InverseProperty("Tags")]
public virtual ICollection<Article>? Articles { get; set; }
}
迁移后,有50篇文章和20个标签,我无法在ArticleId
大于20的(自动生成的)ArticleTag
表中添加新行.
我不知道这是怎么回事,有人能解释一下我做错了什么吗?