Node.js 续写Postgres事务问题
我有一个在profileId和provider字段上具有复合唯一键的表profiles。我使用模型在profiles表中创建记录,代码如下Node.js 续写Postgres事务问题,node.js,postgresql,sequelize.js,Node.js,Postgresql,Sequelize.js,我有一个在profileId和provider字段上具有复合唯一键的表profiles。我使用模型在profiles表中创建记录,代码如下 async function createUserProfile(userProfile){ let transaction; try{ transaction = await sequelize.transaction(); const hyperProfile = await UserHyperProfiles.cre
async function createUserProfile(userProfile){
let transaction;
try{
transaction = await sequelize.transaction();
const hyperProfile = await UserHyperProfiles.create(userProfile, {transaction:transaction});
console.log("profile cretaed");
transaction.commit();
}catch(error){
if(transaction){
transaction.rollback()
}
console.log(error);
}
}
使用上面的代码,即使我没有任何记录,它也会给我唯一的约束错误
SequelizeUniqueConstraintError : Key (provider, profileid)=(google, f123) already exists.
但当我从create调用中删除事务时,它工作得很好。
有什么我遗漏的吗?与您遗漏的问题无关
在事务之前等待。提交和事务。回滚。您在postgres db中真的有(谷歌,f123)
吗?@RatulSharker与在事务之前等待相同的结果。提交()和事务。回滚()(google,123)只是示例值在运行插入之前它们是否存在?