ConstraintError:对象库中已经存在键。在需要升级的方法中

时间:2019-02-05 19:38:30

标签: javascript typescript indexeddb idbobjectstore

我一直在尝试第一次创建对象存储,但是此错误已被消除。

  let IndxDb: IDBFactory;
  let idbOpenDBRequest: IDBOpenDBRequest;
  // set the version of database
  idbOpenDBRequest = this.IndxDb.open(this.dbName, 1);
  idbOpenDBRequest.onupgradeneeded = (e) => {
    const db = e.target.result;
    db.onerror = (err) => {
      console.error(err);
      throw err;
    };
    const corredoresObjectStore = db.createObjectStore('corredor', {keyPath: 'idCorredor'});
    corredoresObjectStore.createIndex('loginCorredor', 'loginCorredor');
    corredoresObjectStore.createIndex('categoriaCorredor', 'categoriaCorredor');
    corredoresObjectStore.createIndex('sexoCorredor', 'sexoCorredor');
    corredoresObjectStore.createIndex('nomeCorredor', 'nomeCorredor');
    corredoresObjectStore.createIndex('CPFCorredor', 'CPFCorredor');
    corredoresObjectStore.createIndex('numCorredor', 'numCorredor');

    const clubeObjectStore = db.createObjectStore('clube', {keyPath: 'idClube'});
    clubeObjectStore.createIndex('loginClube', 'loginClube', {unique: true});

    const eventoObjectStore = db.createObjectStore('evento', {keyPath: 'idEvento'});
    eventoObjectStore.createIndex('idClube', 'idClube');

    const participacaoObjectStore = db.createObjectStore('participacao', {keyPath: 'idParticipacao'});
    participacaoObjectStore.createIndex('idEvento', 'idEvento');
    participacaoObjectStore.createIndex('idCorredor', 'idCorredor');
  };
  idbOpenDBRequest.onsuccess = () => {
    this.db = idbOpenDBRequest.result;
  };
  idbOpenDBRequest.onerror = () => {
    console.error('erro');
    subscriber.error();
  };

当事务创建最后一个对象存储区(participacao)时发生错误。

0 个答案:

没有答案
相关问题