var database = window.indexedDB.open("myTestDatabase", 3);
database.onerror = function(event) {
alert('Error creating database');
}
database.onupgradeneeded = function(event) {
var db = event.target.result;
console.log(1);
//
if (!db.objectStoreNames.contains("data")) {
//Add to indexDB
db.createObjectStore("data", {
keypath: "data"
});
}
}
//If the database is creaed run.
database.onsuccess = function(event) {
var db = event.target.result;
var transaction = db.transaction(["data"], 'readwrite');
//More code here to store data into indexeddb
}
When running my code, I run into the following error: Uncaught NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
When looking at the indexeddb, the "myTestDatabase" is created, but the "data" objectstore is not. What might be the problem with this? It works sometimes, but other times it fails.