2014-06-24 5 views
7

왜 오류가 있습니까?'IDBDatabase'에서 'createObjectStore'를 실행하지 못했습니다.

내 코드 :

var idb = window.indexedDB ||  // Use the standard DB API 
      window.mozIndexedDB || // Or Firefox's early version of it 
      window.webkitIndexedDB; // Or Chrome's early version 

var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction; 
var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange; 

var dbName='nameDb'; 

var idbRequest=idb.open(dbName,'4.67' /*,dbDescription */); 

idbRequest.onsuccess=function (e) { 
    debugger 

    var db=e.target.result; 

    if (!db.objectStoreNames.contains('chat')){ 
     co=db.createObjectStore('chat',{'id':100}); 
    }; 

    if (!db.objectStoreNames.contains('iam')){ 
     co1=db.createObjectStore('iam'); 
    }; 
}; 

idbRequest.onerror = function (e) { 
    debugger 
}; 

Uncaught InvalidStateError: Failed to execute 'createObjectStore' on 'IDBDatabase': The database is not running a version change transaction. index.html:37 idbRequest.onsuccess

+0

"무엇을 의미합니까?" 내게 D – nicael

+0

코멘트. –

+0

귀하의 모든 의견이 다음과 같이 기대됩니다 :-) – nicael

답변

13

당신은 성공의 명령에 objectStore를 만들 수 없습니다. 업그레이드 된 이벤트에서만이 작업을 수행 할 수 있습니다. 문서에서

인용구 :

When you create a new database or increase the version number of an existing database (by specifying a higher version number than you did previously, when Opening a database), the onupgradeneeded event will be triggered. In the handler for this event, you should create the object stores needed for this version of the database

documentation를 참조하십시오.

관련 문제