Dexie.js: ConstraintError thrown on 'put'/'add' or 'bulkPut' operations - Nondescript error message.
Hi, first thanks for this great library. We’re encountering a strange issue, on some clients but not others, when using bulkPut or trying to update or store any new data. But are having difficulty tracking down the source of the issue because of vague error messages and inconsistent reproducibility.
We’re trying to refresh data stored in a Dexie IDB table (it’s identical except one field has been modified), but are receiving errors on constraints for some reason. It seems once the database gets into this state, no more values can be added whatsoever, though reads do work.
Simply doing this, where records is an array of values that do not yet exist in the database (of the same format / integrity that has been stored up to the point where errors start occurring):
await this.database.cards.bulkPut(records)
Results in:
{\"_e\":{},\"name\":\"BulkError\",\"failures\":[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}],\"message\":\"cards.bulkPut(): 45 of 45 operations failed. Errors: ConstraintError: A mutation operation in a transaction failed because a constraint was not satisfied.\"}
However, this error message does not say which constraint was not satisfied - and that information would be very helpful! I suspect it’s not actually a real constraint error, but rather something else happening. I could be mistaken however.

The same code works 90% of the time, but seems to get into this state after 10,000 or so records have been stored – only sometimes. It’s not consistent.
Would appreciate any thoughts or tips on this? Is there a way to find out which constraint was not met?
Database definition:
export class CardDatabase extends Dexie {
static LATEST_VERSION = 1;
readonly cards: Dexie.Table<Card & HasQueriedTimestamp, string>;
constructor() {
super('cardcache');
try {
// INFO: https://dexie.org/docs/Tutorial/Design
// WARNING: DO NOT MODIFY THIS. CREATE A NEW VERSION WTIH UPGRADE BELOW
this.version(CardDatabase.LATEST_VERSION).stores({
cards: '&id,collector_number,name,oracle_id,set_code,[set_code+collector_number],queried'
});
this.cards = this.table('cards');
} catch (error) {
console.error('Failed to init Card Database', error);
throw error;
}
}
}
Additional note: Deleting or renaming the IDB database instance and letting it be re-created by the code above will get things working again, with the same data being saved.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 15
@dfahlander AH. Okay haha. We’re on the same page. Right. So then based on what you said about IDB reporting the error, I’m guessing there’s no way to tell which one was violated during an add/put. Thanks! Much appreciated.
PS. Really interesting to see what you’re doing with Dexie Cloud. Keeping my eye on it 😃