Search code examples
angulardexie

Dexie - Extend existing table with new fields


I'm trying to modify the table structure of an existent table in my Angular2 application using Dexie.

The application already impements version 2 of the table, now I have to extend the mdValuta table with two new informations: f3, f4

This is the code:

super('WEB_IndexedDB');
this.version(1).stores({
  mdValuta:'codudm,numdec,numdecpre'
}); 
this.version(2).stores({
  mdValuta:'codudm,numdec,numdecpre,f1,f2'
});
this.version(3).stores({      
  mdValuta:'codudm,numdec,numdecpre,f1,f2,f3,f4'
});

I don't know why, when I'm executing the application I get this error in the console and no change has been applied to mdValuta table.

OpenFailedError: ConstraintError A mutation operation in the transaction failed because a constraint was not satisfied. For example, an object such as an object store or index already exists and a new one was being attempted to be created.

What I am missing?


Solution

  • Maybe the problem is in the super('WEB_IndexedDB') function... The following code works, creating a version-3 table:

    var db = new Dexie ('WEB_IndexedDB');
    db.version(1).stores({
      mdValuta:'codudm,numdec,numdecpre'
    }); 
    db.version(2).stores({
      mdValuta:'codudm,numdec,numdecpre,f1,f2'
    });
    db.version(3).stores({      
      mdValuta:'codudm,numdec,numdecpre,f1,f2,f3,f4'
    });
    db.open();