Mysql Sequalize bulkCreate导致的Sql错误。但是为什么呢?
此sql查询由bulkCreate从squelize创建。但这有什么不对呢?为什么会出现这种情况Mysql Sequalize bulkCreate导致的Sql错误。但是为什么呢?,mysql,sql,insert,Mysql,Sql,Insert,此sql查询由bulkCreate从squelize创建。但这有什么不对呢?为什么会出现这种情况 code: 'ER_PARSE_ERROR', errno: 1064, sqlState: '42000', sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the righ
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '42000',
sqlMessage: "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 '' at line 1",
sql: "INSERT INTO `account` (`updatedAt`) VALUES ('2021-05-18 11:00:28'),('2021-05-18 11:00:28'),('2021-05-18 11:00:28'),('2021-05-18 11:00:28'),('2021-05-18 11:00:28') ON DUPLICATE KEY UPDATE;",
parameters: undefined
},
sql: "INSERT INTO `account` (`updatedAt`) VALUES ('2021-05-18 11:00:28'),('2021-05-18 11:00:28'),('2021-05-18 11:00:28'),('2021-05-18 11:00:28'),('2021-05-18 11:00:28') ON DUPLICATE KEY UPDATE;",
parameters: undefined
}
您不能在重复密钥更新时使用空
在其中使用任何假赋值-例如,id=id
,其中id
是表的主键。或者updatedAt=updatedAt
但是使用INSERT IGNORE
更简单:
INSERT IGNORE INTO `account` (`updatedAt`)
VALUES ('2021-05-18 11:00:28'),
('2021-05-18 11:00:28'),
('2021-05-18 11:00:28'),
('2021-05-18 11:00:28'),
('2021-05-18 11:00:28');
INSERT IGNORE
如果违反了唯一约束,将生成警告而不是错误,并插入其余行
在这种情况下,根本不需要在重复密钥更新时执行
PS.在定义为唯一的列中插入5个相等值的原因是什么?我看不懂那微小的图像文本。。。复制并粘贴它,并正确设置格式。@jarlh抱歉,完成:)您使用的是哪种dbms?mysql 8/maria DBS您不需要指定重复密钥更新值吗?