Flutter delete Hive Database on Update

5.8k Views Asked by At

I have a Flutter app and I am using Hive to store data.

I have deleted some adapters which were used previously. This caused an error and I have to delete the old database.

Now, if I roll out an update, how do I make sure the old Hive database gets deleted when the user updates the app so that it causes no issues.

3

There are 3 best solutions below

0
On

Instead of deleting, run a database migration.

Hive.box("myBox", version: 5, migrator: (oldVersion, newVersion, box) async {
  await box.delete("unusedKey");
  await box.put("newKey", 7);
});

If you want to delete it anyway,

0
On

Hive.deleteFromDisk() can just wipe it clean.

0
On

You can use box.clear() indeed this is an answer you may be expecting my Best Friend.