简体   繁体   中英

Can't fix 'IdentityUserLogin<string> requires primary key' error

So i have two contexts and i'm using mycontext but i keep getting errors even when mycontext inherits from IdentityDbcontext. I've tried various fixes i found here but none has worked

I used ApplicationUser as the defaultidentity in startup. But to no avail

[My-context] `

public partial class MyContext : IdentityDbContext
    {
        public HMyContext()
        {
        }

        public HRMSDbContext(DbContextOptions<MyContext> options)
            : base(options)
        {
        }`
[Startup]
`services.AddDbContext<MyContext>(options =>
                options.UseSqlServer(
                    Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity<IdentityUser>()
                .AddEntityFrameworkStores<MyContext>();

'

An unhandled exception occurred while processing the request.

InvalidOperationException: The entity type 'IdentityUserLogin' requires a primary key to be defined. Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidateNonNullPrimaryKeys(IModel model)...

As far as I can see you should be passing on the options to the base constructor so:

    public MyContext()
    {
    }

needs to pass on options to base constructor like so.

    public MyContext(DbContextOptions<MyContext> options)
        : base(options)
    {
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM