C#C
C#3y ago
Kroks

❔ EFCore: Duplicate key violates unique constraint

 Exception data:
    Severity: ERROR
    SqlState: 23505
    MessageText: duplicate key value violates unique constraint "PK_ScrapeTargets"
    Detail: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.
    SchemaName: public
    TableName: ScrapeTargets
    ConstraintName: PK_ScrapeTargets
    File: nbtinsert.c
    Line: 666


The exception gets triggered at SaveChangesAsync (in the picture).

one ScrapedUser can have many ScrapeTargets (as Parents) one ScrapeTarget can have many ScrapedUsers (children). So there is n:m mapping. Now I am not adding anything to the scrapetargets table directly, I am just adding the scrapetarget that I queried from the database as parent in a scraped user. I am not sure if its trying to automatically somehow add the referenced scrapetarget in the scrapetargets (which would explain the exception as its trying to add an existing one) or whats happening.
image.png
Was this page helpful?