2

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.

leftjoin
  • 36,950
  • 8
  • 57
  • 116
Raghav Aggiwal
  • 573
  • 2
  • 6
  • 16

3 Answers3

6

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,

shb
  • 5,957
  • 2
  • 15
  • 32
1

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

Pro Co
  • 341
  • 3
  • 10
1

Hive.deleteFromDisk() can just wipe it clean.

chaky
  • 117
  • 2
  • 13