我调用save()
数据库中已存在且已定义主键的对象。
Sequelize告诉我,而不是更新对象id must be unique
。为什么?
我不想说update( {every,single,field,except,the,id})
。太乏味了。
这是我当前的代码:
const instance = db.dbo__peach_payments_transactions.build(existingPayment);
return db.transaction( async (transaction) => {
return instance.save();
});
我现在也尝试过:
return instance.update({fields: [
'updated_at',
'orders_id',
'payment_states_id',
'response_data',
'token',
'result',
'reason_code',
'reason_message',
'price',
'processed_at']});
});
但这会生成相反的sql,而不是保存这些字段,而是updated_at cannot be null
通过使用此sql排除它们,从而给我错误:(即使它不为null):
"INSERT INTO "dbo"."peach_payments_transactions" ("peach_payments_transactions_id","created_at") VALUES ('7fb301e9-bb72-4a70-9ee5-0db1376e83e8','2016-07-11 13:48:20.137 +00:00') RETURNING *;"
您instance.isNewRecord
可以false
在将其发送到服务器之前尝试设置为吗?
sequelize可能正在考虑将其作为新记录,因此它尝试将其插入而不是更新
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句