Cannot use table 'DeviceCodes' for entity type 'DeviceCode' since it is being used for entity type 'DeviceFlowCodes'

Solution 1:

I see ApiAuthorizationDbContext. It seems to me ApiAuthorizationDbContext has DeviceCode table too and you trying to replace ApiAuthorizationDbContext DeviceCode entity with your entity. Change the name your DeviceCode table

Solution 2:

The comment of @Saravanan is exacty. DeviceCode is belong to ASP.NET Core Identity Server . When generate data code, I did not remove it, it was a mistake

public virtual DbSet<DeviceCode> DeviceCodes { get; set; }

and

modelBuilder.Entity<DeviceCode>(entity =>
{
entity.HasKey(e => e.UserCode);

entity.HasIndex(e => e.DeviceCode1, "IX_DeviceCodes_DeviceCode")
    .IsUnique();

entity.HasIndex(e => e.Expiration, "IX_DeviceCodes_Expiration");

entity.Property(e => e.UserCode).HasMaxLength(200);

entity.Property(e => e.ClientId)
    .IsRequired()
    .HasMaxLength(200);

entity.Property(e => e.Data).IsRequired();

entity.Property(e => e.Description).HasMaxLength(200);

entity.Property(e => e.DeviceCode1)
    .IsRequired()
    .HasMaxLength(200)
    .HasColumnName("DeviceCode");

entity.Property(e => e.SessionId).HasMaxLength(100);

entity.Property(e => e.SubjectId).HasMaxLength(200);
});

Solution: Remove these above lines of code.