Search code examples
asp.net-identityentity-framework-coredata-annotations

How to AspNetCore.Identity Custom Fields With Constraints.


I want to add custom fields to AspNetCore.Identity and have done this

   public class ApplicationUser : IdentityUser
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

I tried to do this

   public class ApplicationUser : IdentityUser
    {
        [Required]
        public string FirstName { get; set; }
        [Required]
        public string LastName { get; set; }
    }

but this does nothing.


Solution

  • Generally, if a DB table is not empty, you can't add new columns which are "Not Null".

    Now you can empty the DB and recreate these fields, or alter them manually to Not Null and you will be fine. Of course if there are records and you don't want to loose them, you will need to fill some value in the columns First and Last name