Migrating to Asp.Net Identity 2.0: new columns not being created in AspNetUsers table

前端 未结 7 1492
感情败类
感情败类 2020-12-29 13:28

I get the following error when I try to register a new user, using Identity 2.0 and the default MVC 5 application:

Invalid column name \'Email\'.
Invalid col         


        
7条回答
  •  旧巷少年郎
    2020-12-29 13:38

    You have to modify all the entities that have been updated in version 2.0, for example:

    public partial class AspNetUser
    {    
        public AspNetUser()
        {
            AspNetUserClaims = new HashSet();
            AspNetUserLogins = new HashSet();
            AspNetRoles = new HashSet();
        }
    
        public string Id { get; set; }
    
        [StringLength(256)]
        public string UserName { get; set; }
    
        public string PasswordHash { get; set; }
    
        public string SecurityStamp { get; set; }
    
        [MaxLength(256)]
        public string Email { get; set; }
    
        public bool EmailConfirmed { get; set; }
    
        public string PhoneNumber { get; set; }
    
        public bool PhoneNumberConfirmed { get; set; }
    
        public bool TwoFactorEnabled { get; set; }
    
        public DateTime LockoutEndDateUtc { get; set; }
    
        public bool LockoutEnabled { get; set; }
    
        public int AccessFailedCount { get; set; }
    
        public int UserId { get; set; }
    
        public virtual ICollection AspNetUserClaims { get; set; }
    
        public virtual ICollection AspNetUserLogins { get; set; }
    
        public virtual User User { get; set; }
    
        public virtual ICollection AspNetRoles { get; set; }
    }
    
    public partial class AspNetUserClaim
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
    
        public string ClaimType { get; set; }
    
        public string ClaimValue { get; set; }
    
        [Required]
        [StringLength(128)]
        public string UserId { get; set; }
    
        public virtual AspNetUser AspNetUser { get; set; }
    }
    

    You also need to modify mappings of the entities that changed in the OnModelCreating method of your dbcontext, After this you can add your migration

提交回复
热议问题