Identity icon indicating copy to clipboard operation
Identity copied to clipboard

Identity isn't working on custom properties in ApplicationUser

Open aliarshadpro opened this issue 10 years ago • 2 comments

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; }/

}

aliarshadpro avatar May 05 '16 06:05 aliarshadpro

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);

    }

giddev avatar May 18 '16 09:05 giddev

I'm using a custom ctor that generates a new guid (my id's are based on Guid's)

IsmailHassani avatar Oct 08 '16 21:10 IsmailHassani