Question

I am using the polyfill indexedDBShim Here and I have an error with it and I have no idea how I can debug it or know how I can fix it.

My error :

unable to open database, version mismatch, '1' does not match the currentVersion of '1.0'

It is working fine on the browser that indexedDB is compatible, but when I try it on Safari for example, I have this error..

I just did this :

var request = indexedDB.open( 'products', 1 );
request.onupgradeneeded = function( e ) {
    console.log('Upgrading...');
    var thisDB = e.target.result;

    if ( !thisDB.objectStoreNames.contains( "devices" ) ) {
        thisDB.createObjectStore( "devices", { keyPath: "title" } );
        thisDB.createIndex( "title", "title", { unique: true } );
    }
};

request.onsuccess = function( e ) {
    console.log('Success!');
    that.db = e.target.result;
    //that.saveProducts( data );
};

request.onerror = function( e ) {
    console.log('Error!');
    console.dir( e );
};

Can someone help me with that ?

Was it helpful?

Solution

This shim ends up in some bad business, let me tell you! (We get a lot of questions on it.)

First off, versions should neither be strings nor floats. They should be integers greater than zero per spec. So that ain't right regardless.

From my dash docs on this:

Version numbers are positive whole numbers greater than zero. A programmer can set a database's version manually or implictly by opening an existing database name with a greater version number than the database contains. While a database's name can never change, the database version changes all the time.

Specifying a version greater than the current allows us to entry a "version change" transaction that enables database schema changes. When no version is specified, the database will open with the most recent database version.

Database version numbers are stored as 8-byte "int long long" in the underlying C programming language implementation of IDB and can number anywhere between 1 and 18446744073709551615.

Here's how I'd debug/solve using regular IDB: open up the database without a version. That should open a connection using the most current version and the response object will give you the current version. Compare the two to find your application error.

Notably, database open requests should provide a couple attributes that help you keep a clean and consistant application state when versionchangeing: event.newVersion and event.oldVersion

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top