Dexie Version: [email protected]/dist/dexie.min.js
Chrome: 61.0.3163.100
While attempting to retrieve data via compound primary key, which seems to be set correctly by following examples on http://dexie.org/docs/Compound-Index, I got a SchemaError described below.
This db is newly created, and it's the only version. I tested it several times and the results were the same.

Data and key seem to be stored correctly according to Chrome console.
Thanks! Verified. Solving now.
Sorry, was a little fast with verifying. A wrote a unit test that should verify the issue but it turned out to function as expected (no issue could be verified).
One reason for you seeing this error could be if your local DB schema is not in sync with the declared schema. To work around that, try deleting the DB in browser and run your code again. If that is the case, it may have been a result of changing the primary key (which is not supported).
Please confirm your test works after deleting db. If not, I'd need a repro script/page or PR to a unit test.
Here you go. The code below should reproduce the error. It would seem that the compound key only works if the schema is recreated on every page load but fails if the schema is only created once.
'use strict';
const dbName = 'testDb';
const db = new Dexie(dbName, { autoOpen: false });
db.open().then(() => {
return db.table('foo').bulkPut([{
fid: 'abc', uid: 'xyz'
}]);
}).then(() => {
return db.table('foo').where({
fid: 'abc', uid: 'xyz'
}).first();
}).then(console.info).catch((e) => {
if (e.name === 'NoSuchDatabaseError') {
console.info(`Will create ${dbName}. Subsequent page loads/reloads will produce "SchemaError: KeyPath [fid+uid] on object store foo is not indexed"`);
db.version(1).stores({
foo: '[fid+uid]'
});
db.open();
} else {
console.error(e);
}
});
Thanks. It turns out it triggers only when dynamically opening the DB and when also there are exacly two propertys in the index (not three).
EDIT: Not really true. It's a bug in dexie 2.x (no matter the number of propertys included in the index), but it will only trigger when opening db dynamically
Ok, this is a bug in dexie@latest (2.x) but has already been solved in master while I rewrote the entire code into typescript (dexie@next).
So I will close the issue as was already fixed.
To get the fix , use npm install dexie@next or else you could also work around the bug by defining db.version() always instead of opening it dynamically. You don't actually need catching NoSuchDatabase. See Creating Database vs. opening existing.
Thanks for the pointer. So do we always run the declarative db.version(/*n*/).stores({/* ... */}) like the code below?
'use strict';
const dbName = 'testDb';
const db = new Dexie(dbName, { autoOpen: false });
db.version(1).stores({
foo: '[fid+uid]'
});
db.open().then(() => {
return db.table('foo').bulkPut([{
fid: 'abc', uid: 'xyz'
}]);
}).then(() => {
return db.table('foo').where({
fid: 'abc', uid: 'xyz'
}).first();
}).then(console.info).catch(console.error);
Yes, and other benefits always declaring db are that you :
Most helpful comment
Ok, this is a bug in dexie@latest (2.x) but has already been solved in master while I rewrote the entire code into typescript (dexie@next).
So I will close the issue as was already fixed.
To get the fix , use
npm install dexie@nextor else you could also work around the bug by defining db.version() always instead of opening it dynamically. You don't actually need catching NoSuchDatabase. See Creating Database vs. opening existing.