Identity isn't working on custom properties in ApplicationUser
I am working on the login system of my project; the error I am facing is that when I use the default attributes of AspNetUser it is working fine but when I create the custom attributes using ApplicationUser Class; I am getting this error every time. Please help me out.
Error:
A database operation failed while processing the request.
DbUpdateException: An error occurred while updating the entries. See the inner exception for details. SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_IdentityUserClaim
_ApplicationUser_UserId". The conflict occurred in database "payamber", table "dbo.AspNetUsers", column 'Id'. There are pending model changes for ApplicationDbContext
Scaffold a new migration for these changes and apply them to the database from the command line:
dnx ef migrations add [migration name] dnx ef database update
My ApplicationUser Class: public class ApplicationUser : IdentityUser { public string FirstName { set; get; } public string MiddleName { set; get; } public string LastName { set; get; } /public DateTime AddedOn { set; get; } public ApplicationUser ReviewedBy { set; get; } public DateTime ReviewedOn { set; get; } public bool IsActive { set; get; } public bool IsConfirmed { set; get; }/
}
Is it not because you have cascading deletes enabled?
Try disable it
protected override void OnModelCreating(ModelBuilder builder)
{
//disable cascading deletes
foreach (var relationship in builder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
relationship.DeleteBehavior = DeleteBehavior.Restrict;
}
base.OnModelCreating(builder);
}
I'm using a custom ctor that generates a new guid (my id's are based on Guid's)