DB Query Commands Produce Weird SQL Queries
I have my model:
type Report struct {
ID int `json:"id,omitempty" gorm:"primary_key"`
Title *string `json:"title" gorm:"not null"`
}
I have initialized the variable report
as var report Report
I have successfully auto-migrated this model as a database table and populated the database as sql INSERT
with GORM db.Create(&report)
.
The problem I'm running into is trying to execute query commands. Each command requests supported GORM, such as db.Find(&report)
, db.First(&report, 1)
leads to such requests as folows:
SELECT * FROM "reports" WHERE "reports"."deleted_at" IS NULL AND ((id = $1))
SELECT * FROM "reports" WHERE "reports"."deleted_at" IS NULL AND ((id = $1))
SELECT * FROM reports WHERE (reports.deleted_at IS NULL) AND ((id = $1))
SELECT * FROM reports WHERE (reports.deleted_at IS NULL) AND ((id = $1))
SELECT 0 done
I cannot query the database. I am using GORM with db cockroach. This works great when using GO pq drivers and raw sql commands.
source to share
The column deleted_at
is part of the GORM basegorm.Model
struct and soft delete . Are you using gorm.Model
somewhere that we don't see in this example? This shouldn't happen if you don't define a field with a name DeletedAt
or embed a gorm.Model
into your model structure.
source to share