0

I defined one collection without any problem as follows:

db = new Dexie('db');
db.version(1).stores(
    {test : '++id,title'}
); 

but when i add a new table to 'db' database by two ways below, both is failed and change does not happen.

//without version change
db = new Dexie('db');
db.version(1).stores(
    {test2 : '++id,title'}
); 

or

//with version change
db = new Dexie('db');
db.version(2).stores(
    {test2 : '++id,title'}
); 
mohammad ali
  • 109
  • 1
  • 5

1 Answers1

0

The second alternative is the correct one. But keep version 1 code as well, as described in the docs. However, it can easily get wrong in case you've already tested to use version 2 or a version 3 already. You can never change the same version on the same client.

If your second alternative fails, check in the console log for an explaining message. It might be that you've already added a version above 2 while testing around. If so, you might need to either increment the version to a value higher than what has been used, or do

Dexie.delete('db').then(()=>db.open())

The above line will delete the database and then recreate it.

David Fahlander
  • 5,058
  • 1
  • 20
  • 19
  • 1
    also please note i want add a new table in database and not change in existed table, as you can see there is not test2 table in version 1. in this way we have increase version? – mohammad ali Oct 09 '17 at 11:33
  • How do we know if version incrementation is needed? new Dexie(dbName) always causes db.verno = 0, so it not possible to properly increment db schema version dynamically. We should know what verno is set before updating the schema.... Is it Indexedb limitation? – Marek Marczak Dec 06 '21 at 09:02
  • await db.open(). Then verno shows actual version – David Fahlander Dec 07 '21 at 09:05