2

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.

Brett Zamir
  • 14,034
  • 6
  • 54
  • 77
user3500506
  • 133
  • 1
  • 8

1 Answers1

4

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.

user3500506
  • 133
  • 1
  • 8
  • Tnx! Just experience the same error. It's a pain working with IndexedDB: tons of handlers, DB-version is confusing and that what you experienced.... – Jonny Aug 08 '18 at 20:58