I have a field in my MySQL database called key.

My code: ... .Where("key = ?", key) ...

Unfortunately the generated sql does not put backticks so mysql spits out an error. This is because the term key is a keyword in Mysql.

Perhaps you can put a check in in the Where function and automatically put backticks if the field is "key"

Comment From: danhardman

Would this work as a suitable fix? I don't think GORM should encourage users to use MySQL keywords. It isn't good practice to do so anyways.

.Where("`key` = ?", key)

Comment From: ppd0705

I met the same problem, have you already solved it?

Comment From: ppd0705

Would this work as a suitable fix? I don't think GORM should encourage users to use MySQL keywords. It isn't good practice to do so anyways.

.Where("`key` = ?", key)

this would meet panic: panic: reflect: reflect.Value.Set using unaddressable value

Comment From: ppd0705

I found one way: DB.Raw("SELECT * FROM `table_name` WHERE `keyword` = ?", value).Rows()