Upsert Problem on Multiple Columns Unique Key (MySQL)
Author: ceshihaoCreated Jul 9, 2018Updated Jul 11, 2025
Labelsbughelp wanted
Upsert() returns a error cannot upsert with a table that cannot conflict on a unique column.
What version of SQLBoiler are you using (sqlboiler --version)?
SQLBoiler v3.0.0-rc9
If this happened at runtime what code produced the issue? (if not applicable leave blank)
Yes
Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)
CREATE TABLE `test` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`node_id` int(11) NOT NULL,
`node_type` varchar(32) NOT NULL DEFAULT '',
`parameter` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `node_id_type` (`node_id`,`node_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;Further information. What did you do, what did you expect?
Upsert() can work well with Multiple Columns Unique Key.
After a quick investigation, I find the error is from
var mySQLTestUniqueColumns = []string{
"id",
}
func (o *Test) Upsert(ctx context.Context, exec boil.ContextExecutor, updateColumns, insertColumns boil.Columns) error {
...
nzUniques := queries.NonZeroDefaultSet(mySQLTestUniqueColumns, o)
if len(nzUniques) == 0 {
return errors.New("cannot upsert with a table that cannot conflict on a unique column")
}
...
}Source: aarondl/sqlboiler