我正在使用 React 16.3.2、Redux 4 和 Dexie 2.0.3 进行开发。
当我尝试第二次存储数据时,会抛出以下错误信息:
Error: ConstraintError: Key already exists in the object store.
return dispatch => {
db.table
.add(data)
.then (function(id){
console.log(id)
})
.catch (function (error) {
console.log("Error: " + error);
});
}
我的数据库结构:
const db = new Dexie('ReactReduxDexieJsCRUD');
db.version(1).stores({table:'++id,name,age,bloodGroup,donateBefore,weight' });
第一次存储日期时,它能够正常工作,但之后会出现错误。
put(data)
代替add(data)
。 - Oblosys