none
Migration Issue with ASP.NET Core 2.2 “cannot be marked as nullable/optional because it has been included in a key” RRS feed

  • Question

  • I have the issue after I type the following command with ASP.NET Core 2.2:
    dotnet ef migrations add AddLoginLogoutTime --context xxxContext

    and get the following error for the IdentityServer 4

    The property 'Id' on entity type 'Microsoft.AspNetCore.Identity.IdentityRole' cannot be marked as nullable/optional because it has been included in a key {'Id'}.

    namespace Community.Data.Entities.Users
    {
        // Add profile data for application users by adding properties to the ApplicationUser class
        public class ApplicationUser : IdentityUser
        {
            public string FullName { get; set; }
    
            public long CompanyId { get; set; }
    
            public long? BeforeSpyingOriginalCompanyId { get; set; }
    
            public bool IsResetPasswordUponLoginNeeded { get; set; }
    
            public bool IsWelcomingFromTraditionalWebsiteNeeded { get; set; }
    
            public bool Status { get; set; } = true;
    
            public bool IsSubscribeWhatsAppMessage { get; set; } = true;
    
            public DateTime CreatedAt { get; set; } = DateTime.Now;
    
            [MaxLength(50)]
            public string VerificationCode { get; set; }
    
            public DateTime VerificationCodeExpiryDate { get; set; } = DateTime.Today.ToSqlDefaultDateTime();
    
            public DateTime LoginTime { get; set; } = DateTime.Now;
    
            public DateTime LogoutTime { get; set; } = DateTime.Now;
        }
    }
    Anyone facing this issue and how to solve the error?



    I am newbie in enterprise as developer.

    • Moved by CoolDadTx Tuesday, January 15, 2019 2:56 PM ASP.NET related
    Tuesday, January 15, 2019 10:11 AM

All replies

  • Hello,

    I would recommend posting your question under issues on GitHub EntityFrameworCore page.

    https://github.com/aspnet/EntityFrameworkCore/issues


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, January 15, 2019 10:50 AM