踩到的坑:发现upsert 只插入不能更新。
最近禁网又不能翻墙,所以百度了一圈没找到答案,只能读官方文档,折腾半小时~,泪奔
解决:
在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.)特别注意,刚开始眼瞎没看到~
Otherwise you may experience a unique constraint violation, because sequelize fails to identify the row that should be updated.