Golang-Gorm-PostgreSQL Upsert Hatası

uriones

Picopat
Katılım
20 Ekim 2023
Mesajlar
51
Çözümler
1
Yer
Denizli
Daha fazla  
Cinsiyet
Erkek
Meslek
Mid-Level Backend Developer 💙 Golang
Kod:
const (WishRejected WishStatus = iota - 1
WishWaiting
WishFirstManagerApproved
WishSecondManagerApproved
WishApproved
)

type WishType struct {
ID uint           `gorm:"primarykey" json:"id"`
ParentID      int            `gorm:"type:integer" json:"parent_id"`
Parent        *WishType      `gorm:"foreignKey:ParentID" json:"parent_data,omitempty"`
RelatedUserID int            `gorm:"type:integer" json:"related_user_id"`
RelatedUser   *User          `gorm:"foreignKey:RelatedUserID" json:"related_user_data,omitempty"`
CreatedAt     time.Time      `json:"-"`
UpdatedAt     time.Time      `json:"-"`
DeletedAt     gorm.DeletedAt `gorm:"index" json:"-"`
Name          string         `gorm:"type:varchar(255)" json:"name"`
IsProcess     bool           `gorm:"type:boolean" json:"is_process"`
IsDateRange   bool           `gorm:"type:boolean" json:"is_date_range"`
IsGrantWish   bool           `gorm:"type:boolean" json:"is_grant_wish"`
}

type ProcessTrack struct {
WishID int   `json:"wish_id,omitempty"`
UserID     int   `json:"user_id,omitempty" gorm:"type:integer"`
User       *User `json:"user_data,omitempty" gorm:"foreignKey:UserID"`
ChiefID    int   `json:"chief_id,omitempty" gorm:"type:integer"`
Chief      *User `json:"chief_data,omitempty" gorm:"foreignKey:ChiefID"`
IsApproved *bool `json:"is_approved,omitempty" gorm:"type:boolean"`
}

type Wish struct {
ID int                `gorm:"primarykey;autoIncrement" json:"id"`
CreatedAt         time.Time          `json:"created_at"`
UpdatedAt         time.Time          `json:"updated_at"`
DeletedAt         gorm.DeletedAt     `gorm:"index" json:"deleted_at"`
UserID            int                `json:"user_id"`
WishTypeID        int                `json:"wish_type_id"`
WishType          *WishType          `gorm:"foreignKey:WishTypeID" json:"wish_type_data,omitempty"`
ProcessTrack      []*ProcessTrack    `gorm:"foreignKey:WishID" json:"process_track,omitempty"`
VacationDateRange *VacationDateRange `gorm:"foreignKey:WishID" json:"vacation_date_range,omitempty"`
Content           string             `gorm:"type:varchar(255)" json:"content"`
Status            WishStatus         `gorm:"type:integer" json:"status"`
}

type VacationDateRange struct {
StartDate *time.Time `gorm:"type:timestamp" json:"start_date"`
WishID      int        `gorm:"type:integer"`
EndDate     *time.Time `gorm:"type:timestamp" json:"end_date"`
BioSignData string     `gorm:"type:varchar(255)"`
}

Genel olarak yapılarım bu şekilde ve basit bir Create işlemi yapıyorum. Değerler yerine oturuyor ama kayıt yapmaya çalıştığımda vacationDateRanges kısmı alttaki hatayı veriyor.
ERROR: ON CONFLICT DO UPDATE requires inference specification or constraint name (SQLSTATE 42601)

Çıkardığı SQL sorgusu da alttaki şekilde.
SQL:
NSERT INTO "vacation_date_ranges" ("start_date","wish_id","end_date","bio_sign_data") VALUES ('2023-07-06 14:20:19.263',1,'2023-07-06 14:20:19.263','') ON CONFLICT DO UPDATE SET "wish_id"="excluded"."wish_id"

hatayı nasıl çözerim.

Up
 
Son düzenleme:

Geri
Yukarı