1
I’m having trouble updating the version of Indexeddb, it presents the following errors.
Uncaught Constrainterror: Failed to execute 'createObjectStore' on 'Idbdatabase': An Object store with the specified name exists already. index.js:11 Errorundefined index.js:162 Uncaught Invalidstateerror: Failed to execute 'transaction' on 'Idbdatabase': The database Connection is closing.
My code:
var request = indexedDB.open("DB_TESTE", 3);
var db = null;
request.onupgradeneeded = function(){
db = request.result;
//////////////////////////////////////////////////////////////
// TABELA PESSOA //
////////////////////////////////////////////////////////////
var pessoa = db.createObjectStore("tbl_PESSOAS", {keyPath: "COD_IDENT_PESSO"});
pessoa.createIndex("COD_IDENT_PESSO", "COD_IDENT_PESSO", {unique: true});
pessoa.createIndex("TXT_NOMEX_PESSO", "TXT_NOMEX_PESSO", {unique: false});
pessoa.createIndex("TXT_APELI_PESSO", "TXT_APELI_PESSO", {unique: false});
pessoa.createIndex("TXT_FONEX_PESSO", "TXT_FONEX_PESSO", {unique: false});
pessoa.createIndex("DAT_NASCI_PESSO", "DAT_NASCI_PESSO", {unique: false});
pessoa.createIndex("TXT_NASCI_PESSO", "TXT_NASCI_PESSO", {unique: false});
pessoa.createIndex("TXT_NATUR_PESSO", "TXT_NATUR_PESSO", {unique: false});
pessoa.createIndex("FLG_SEXOX_PESSO", "FLG_SEXOX_PESSO", {unique: false});
pessoa.createIndex("FLG_ESTAD_CIVIL", "FLG_ESTAD_CIVIL", {unique: false});
pessoa.createIndex("FLG_IDENT_PESSO", "FLG_IDENT_PESSO", {unique: false});
pessoa.createIndex("TXT_EMAIL_PESSO", "TXT_EMAIL_PESSO", {unique: false});
pessoa.createIndex("TXT_SENHA_USUAR", "TXT_SENHA_USUAR", {unique: false});
pessoa.createIndex("BLO_FOTOX_PESSO", "BLO_FOTOX_PESSO", {unique: false});
pessoa.createIndex("TXT_ENDER_CEPXX", "TXT_ENDER_CEPXX", {unique: false});
pessoa.createIndex("TXT_ENDER_BAIRR", "TXT_ENDER_BAIRR", {unique: false});
pessoa.createIndex("TXT_ENDER_LOGRA", "TXT_ENDER_LOGRA", {unique: false});
pessoa.createIndex("TXT_ENDER_NUMER", "TXT_ENDER_NUMER", {unique: false});
pessoa.createIndex("TXT_ENDER_COMPL", "TXT_ENDER_COMPL", {unique: false});
pessoa.createIndex("COD_IDULT_ATUAL", "COD_IDULT_ATUAL", {unique: false});
pessoa.createIndex("DAT_ULTIM_ATUAL", "DAT_ULTIM_ATUAL", {unique: false});
}
request.onsuccess = function(){
//database connection established
db = request.result;
console.log("Conectado corretamente");
}
request.onerror = function(event){
console.log("Error" + event.target.errorCode);
}
The Objects are persistent, they will not be erased without you sending, so you cannot try to create them again with the
createObjectStore
– Rafael Telles
How do I erase them ?
– Renan Rodrigues
Using the method
deleteObjectStore
(https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/deleteObjectStore)– Rafael Telles
Gave this error Uncaught Typeerror: Undefined is not a Function
– Renan Rodrigues
What are you calling?
– Rafael Telles
And where are you declaring "indexedDB"?
– Rafael Telles
Just above, var request = indexedDB.open("DB_MINHACELULA", 4); var db = null;
– Renan Rodrigues
Try to use something like
db.deleteObjectStore(...)
– Rafael Telles
Have some way to delete entire database, not just table and create everything again, with version 1 ?
– Renan Rodrigues
Type a reset in memory, to start, because at the time saved it starts saving the number where it stopped, ie not deleted the table and did not create another.
– Renan Rodrigues
Let’s go continue this discussion in chat.
– Rafael Telles