踩到的坑:發(fā)現(xiàn)upsert 只插入不能更新餐曼。
最近禁網(wǎng)又不能翻墻压储,所以百度了一圈沒(méi)找到答案鲜漩,只能讀官方文檔,折騰半小時(shí)~集惋,淚奔
解決:
在Model層也要聲明唯一索引孕似,要不然不生效。
先看下官方文檔:
public?static?upsert(values:?Object, options:?Object):?Promise<boolean>
Insert or update a single row. An update will be executed if a row which matches the supplied values on either the primary key or a unique key is found.
?(Note that the unique index must be defined in your sequelize model and not just in the table.)特別注意刮刑,剛開(kāi)始眼瞎沒(méi)看到~
?Otherwise you may experience a unique constraint violation, because sequelize fails to identify the row that should be updated.
?