似乎与aspnetuser无关,外键冲突

时间:2019-08-25 20:35:34

标签: c# database asp.net-core

我正在尝试与初始aspnetusers设置建立一对多关系。似乎无法使其正常工作,有人知道如何修复它吗?

public class ApplicationUser:IdentityUser
{
    public virtual ICollection<UserMovieData> UserMovieDatas { get; set; }
}

public class UserMovieData
{
    public int UserMovieDataId { get; set; }
    public string ImdbId { get; set; }
    public bool Favorited { get; set; }
    public double Rating { get; set; }
    public string Review { get; set; }
    public string ApplicationUserId { get; set; }

    public virtual ApplicationUser ApplicationUser { get; set; }
}

modelBuilder.Entity<UserMovieData>()
            .HasOne(p => p.ApplicationUser)
            .WithMany(b => b.UserMovieDatas)
            .HasForeignKey(p => p.ApplicationUserId);

错误:

  

ALTER TABLE语句与FOREIGN KEY约束“ FK_UserMovieData_AspNetUsers_applicationUserId”冲突。在数据库“ ____”,表“ dbo.AspNetUsers”的“ Id”列中发生了冲突。

0 个答案:

没有答案