model.DB.Where("show = ?", 1).Debug().Find(&plans)
model.DB.Where("id = ?", 1).Debug().Find(&plans)

第一条debug,执行失败

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'show = ?' at line 1
[0.115ms] [rows:0] SELECT * FROM `v2_plan` WHERE show = 1

第二条debug,执行成功

[0.809ms] [rows:1] SELECT * FROM `v2_plan` WHERE id = 1

针对show这个检索,使用struct可以查询成功 model.DB.Where(&model.Plan{Show: 1}).Debug().Find(&plans)

[1.087ms] [rows:4] SELECT * FROM `v2_plan` WHERE `v2_plan`.`show` = 1

或者使用 model.DB.Where("show", 1).Debug().Find(&plans) 也可以成功

[1.359ms] [rows:4] SELECT * FROM `v2_plan` WHERE `show` = 1

Comment From: Septrum101

应该是show是内置关键字,必须加`show`来转义。非要使用string条件可以使用

model.DB.Where("`show`= ?", 1).Debug().Find(&plans)

来查询

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking