.NET Core 2.x Identity int foreign key cannot target int primary key

The exception message is not quite clear, but usually indicates improper model configuration.

There are several factors to be considered here.

First, in version 2.0 the navigation properties have been removed from identity model, and the base IndentityDbCOntext implementation explicitly configures the relationships with no navigation property at either side.

The last is very important. EF Core uses conventions, data annotations and explicit configuration (via fluent API), with conventions being a lowest priority and explicit configuration being the highest priority. What that means is that data annotations can override conventions, but not explicit configuration. Explicit configuration can override both conventions and data annotations, as well as the previous explicit configuration (the last wins). In other words, the only way to override explicit configuration is to use fluent API after the base configuration.

Since your model adds some navigation properties, you have to re configure the relationships to reflect that. The common mistake with relationship configuration is to use the Has / With methods without specifying the navigation property name / expression when in fact the model do have navigation property. Logically you think that skipping the optional argument means use default, but here it actually means no navigation property. Which in turn leads to the following unexpected behavior.

The navigation properties are still discovered by EF. Since they are not a part of a configured relationship, EF considers them being a part of a separate relationship and conventionally maps them with default shadow FK property / column name. Which is definitely not what you want.

There is no need to configure the relationship twice. Actually it's better to configure it once, but using the correct With / Has call arguments that represent the presence / absence of the navigation property at that end.

With that being said, you have to override OnModelCreating, call the base implementation and then add the following to reflect the navaigation properties introduced in your identity model derived entities:

builder.Entity<AspNetUserRole>()
    .HasOne(x => x.AspNetUser)
    .WithMany(x => x.AspNetUserRoles)
    .HasForeignKey(x => x.UserId);

builder.Entity<AspNetUserRole>()
    .HasOne(x => x.AspNetRole)
    .WithMany(x => x.AspNetUserRoles)
    .HasForeignKey(x => x.RoleId);

and similar for other navigation properties like AspNetRole.AspNetRoleClaims collection etc. For more info, see the Relationships EF Core documentation topic explaining different relationship configurations

Also, since by default the IdentityUserRole is (again explicitly) configured to use composite PK ({ UserId, RoleId }) and your derived AspNetUserRole entity defines its own PK (Id), you should also explicitly specify that:

builder.Entity<AspNetUserRole>()
    .HasKey(e => e.Id);