英文:
IndexedDB: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found
问题
我刚刚为我的React PWA启动了一个indexedDB,并且遇到了以下错误。
Uncaught DOMException: 在'IDBDatabase'上执行'transaction'操作失败:找不到指定的对象存储之一。位于request.onsuccess
问题出现在这一行:
const transaction = db.transaction("storeName", "readwrite");
我编写的函数如下:
const handleSubmit = (event) => {
event.preventDefault();
const request = window.indexedDB.open("NewApp", 1);
request.onsuccess = () => {
if (nameArea && enterDate) {
const db = request.result;
const transaction = db.transaction(["apps"], "readwrite");
const store = transaction.objectStore("apps");
store.put({ nameArea, enterDate: Date.now() });
const query = store.get(1);
query.onsuccess = function () {
console.log("下一个信息", query.result);
};
transaction.oncomplete = function () {
// db.close();
};
}
};
request.onerror = function (event) {
console.error("IndexedDB发生错误");
console.error(event);
};
};
这个问题只在新打开的浏览器中出现,当我调试时,记录被添加,但不仅仅是空字符串。
英文:
I just start a indexedDB for my react PWA. And i get this error.
Uncaught DOMException: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. at request.onsuccess
line is : const transaction = db.transaction("storeName", "readwrite");
and the func i did:
const handleSubmit = (event) => {
event.preventDefault();
const request = window.indexedDB.open("NewApp", 1);
request.onsuccess = () => {
if (nameArea && enterDate) {
const db = request.result;
const transaction = db.transaction(["apps"], "readwrite");
const store = transaction.objectStore("apps");
store.put({ nameArea, enterDate: Date.now() });
const query = store.get(1);
query.onsuccess = function () {
console.log("next info", query.result);
};
transaction.oncomplete = function () {
/db.close();
};
};
request.onerror = function (event) {
console.error("An error occurred with IndexedDB");
console.error(event);
};
}
};
That problem is in only new opened browser, when i debug it records are adding but not only empty string.
答案1
得分: 1
这意味着要么对象存储尚未创建,要么您正在使用已过时的数据库连接。如果在另一个标签页中升级了数据库,则需要通过在“versionchange”事件中重新打开数据库来升级连接。
英文:
It means either that the object stores have not yet been created, or you are using an outdated db connection.
If the database has been upgraded in another tab, you need to upgrade the connection by re-opening the database in the versionchange
event.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论