user3500506
user3500506

Reputation: 143

db.js - Trouble adding a record to IndexedDB

I'm not sure what I've done wrong here. This is almost identical to the db.js example. I see the indexeddb in my developer tools, but I can't figure out why adding a record is throwing this error:

Uncaught DataError: Failed to execute 'add' on 'IDBObjectStore': The object store uses out-of-line keys and has no key generator and the key parameter was not provided.

Here's my schema:

schema: {
        previews: {
            key: { 
                keyPath: 'id',
                autoIncrement: true 
            },
            indexes: {
                pid: { unique: true },
                title: { },
                url: { }
            }
        }
    }

And my add call:

server.previews.add({
    pid: p,
    title: t,
    url: u
});

I originally had the title and url fields in my indexes, but really, I only need to be able to search by the pid.

I've also tried passing in id: 1 both inside and outside the object, but the same error.

Upvotes: 2

Views: 1835

Answers (1)

user3500506
user3500506

Reputation: 143

I found the solution. The above code does work fine. This was several iterations in to trying to make it work and I was assuming that the db was being rebuilt to match my schema definition when I updated it. It wasn't. I manually deleted the db through the Chrome options and when I reloaded, it rebuilt the db and everything works.

Upvotes: 4

Related Questions