EF Core 2.1 project Add-Migration NullReferenceException

末鹿安然 提交于 2019-12-06 03:42:01

Looks like this error was caused by some references to models in my ModelSnapshot class that did not exist anymore. Including some Identity models that were left behind after I removed AspNetCore.Identity from the Context.

Deleting the code below from my EscData01ContextModelSnapshot fixed the issue.

modelBuilder.Entity("Sms.Office.Data.EscData01.Models.ExcelTemplate", b =>
{
    b.HasOne("Sms.Office.Data.EscData01.Models.File", "File")
        .WithMany()
        .HasForeignKey("FileId")
        .OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
    b.HasOne("Sms.Office.Data.EscData01.Authentication.ApplicationRole")
        .WithMany()
        .HasForeignKey("RoleId")
        .OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
     b.HasOne("Sms.Office.Data.EscData01.Authentication.ApplicationUser")
         .WithMany()
         .HasForeignKey("UserId")
         .OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
     b.HasOne("Sms.Office.Data.EscData01.Authentication.ApplicationUser")
         .WithMany()
         .HasForeignKey("UserId")
         .OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
     b.HasOne("Sms.Office.Data.EscData01.Authentication.ApplicationRole")
         .WithMany()
         .HasForeignKey("RoleId")
         .OnDelete(DeleteBehavior.Cascade);
     b.HasOne("Sms.Office.Data.EscData01.Authentication.ApplicationUser")
         .WithMany()
         .HasForeignKey("UserId")
         .OnDelete(DeleteBehavior.Cascade);
});   
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
     b.HasOne("Sms.Office.Data.EscData01.Authentication.ApplicationUser")
         .WithMany()
         .HasForeignKey("UserId")
         .OnDelete(DeleteBehavior.Cascade);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!