Open hiren-jarvisbitz opened 2 years ago
Don't know what hospitalUpdate() does but else than that, the principle is to create a new Dexie instance, open it using an incremented version and the new schema.
There is sample code for dynamic schema manipulation using a function changeSchema()
in the docs of [Dexie.open()#dynamic-schema-manipulation](https://dexie.org/docs/Dexie/Dexie.open()#dynamic-schema-manipulation)
@dfahlander Thanks! Your answer helps me a lot. And I want to confirm a problem. I have my Electron desktop application which use Dexie db. Now I think I must upgrade db version to create a new table in my lastest version of application (e.g. db verison 10 to 20 dynamically) . So when I open my old application, my code must open the db at verison 20 dynamically to read data correctly, is it right?
Because I get an error like this before:
VersionError: The requested version (10) is less than the existing version (20).
My db is on version 20, but my code still tries to open it at version 10.
@dfahlander Yes, I'm also getting the same error as well.
Open failed: VersionError: The requested version (20) is less than the existing version (30). VersionError: The requested version (20) is less than the existing version (30).
You need to open the db without specifying a version.
https://dexie.org/docs/Dexie/Dexie.open()#sample-dynamic-mode
The only downside is that your tables need to be accessed via
db.table('myTableName')
instead of
db.myTableName
Want to create a new table with the existing dexie index DB. But here don't want to delete my previous DB data or not to clear cache.
Currently created DB function as below.
I have tried the below code to create a new table with the existing DB.: