I have the following structs:
type Report struct {
ID uuid.UUID
CreatedAt time.Time
UpdatedAt time.Time
Date time.Time
Rows []Row `gorm:"constraint:OnDelete:CASCADE;"`
}
type Row struct {
ID uuid.UUID
CreatedAt time.Time
UpdatedAt time.Time
ReportID uuid.UUID
Value string
}
And I want to be able to delete the reports like this:
db.Where("1 = 1").Delete(&Report{})
But I get pq: update or delete on table "reports" violates foreign key constraint "fk_report_rows_reports" on table "report_rows"
, but should not be Row also be deleted since I added the OnDelete:CASCADE?