ConstraintError: Unable to add key to index 'nameNative': at least one key does not satisfy the uniqueness requirements.
Brand new to the library here. I have been reading the documentation for a while and fiddling with this for some time now. No idea what is wrong?
I had this -
db.version(1).stores({
languages: '++id,identifier,&name,&nameNative',
courses: '++id,name,languageFrom,languageTo',
vocabulary: '++id,courseId,source,destination'
});
And it just throws a ConstraintError when I tried to call this function -
async function seedDatabase() {
await db.languages.add({identifier: 'en', name: 'English', nameNative: 'English'});
await db.languages.add({identifier: 'sv', name: 'Swedish', nameNative: 'Svenska'});
await db.courses.add({name: 'Swedish', languageFrom: 'en', languageTo: 'sv'});
await db.vocabulary.add({courseId: 1, source: 'a man', destination: 'en man'});
await db.vocabulary.add({courseId: 1, source: 'a woman', destination: 'en kvinna'});
};
But -
- With the
namekey,EnglishandSwedishare definitely both unique... no? - With the
nameNativekey,EnglishandSvenskaare definitely both unique... no?
I tried this without the & and the problem persists.
Here's the full error -

Okay, at some point in my fumbling around it appears to have actually created the database and (mostly) populated it.
Both languages were added, the course was added but only the first vocabulary item was added. If I try to add a second one now, I get the same old error.
This library/IndexedDB doesn't really make much sense to me?
Hmm, I deleted all the databases via the dev-tools and then I changed to using bulkAdd and I've since had no problems. Any ideas on why this happened?
我看了,你这里应该是想 复合索引唯一,那么不是 languages: '++id,identifier,&name,&nameNative', 而是应该是languages: '++id,identifier,name,nameNative,&[name+nameNative]', 这样可以控制 name+nameName 唯一。