GORM Playground Link

https://github.com/go-gorm/playground/pull/652

Description

Explain your user case and expected results

I'm using a composite primary key for a table that references a list of entities in another table.

The error I get is

2023/10/02 15:24:09 testing postgres...

2023/10/02 15:24:10 gorm-playground/main_test.go:13 ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
[0.952ms] [rows:0] INSERT INTO "tags" ("pet_first_name","pet_last_name","name") VALUES ('Hasso','McDog','foo') ON CONFLICT DO UPDATE SET "pet_first_name"="excluded"."pet_first_name","pet_last_name"="excluded"."pet_last_name"

2023/10/02 15:24:10 gorm-playground/main_test.go:13 ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
[3.761ms] [rows:1] INSERT INTO "pets" ("first_name","last_name") VALUES ('Hasso','McDog')
--- FAIL: TestGORM (0.00s)
    main_test.go:14: ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)
FAIL
FAIL    gorm.io/playground  0.238s

Comment From: fragoulis

There is a chance that you need to explicitly declare which columns make up he primary key using gorm tags as such:

type UserIdentifier struct {
    UserID     uuid.UUID `gorm:"primaryKey"`
    SubID      string    `gorm:"primaryKey"`
    AuthSystem string    `gorm:"primaryKey"`
}

Otherwise gorm cannot build the correct sql.

Comment From: johannes-riecken

@fragoulis Thanks for answering. I did explicitly declare the primary key columns when I wrote this issue, as you can see in the playground link on top.