0

I have a flutter app that stores the data with objectbox but I need to change a class that has

// old:
int year;
// new:
double year;

ObjectBox does not support migrating existing property data to a new type. You will have to take care of this yourself, e.g. by keeping the old property and adding some migration logic.

On the objectbox page they say it's possible through migration logic. Data is already stored with int and I need to migrate this data to double but I have not succeeded. Could someone help me with an example. Thanks

1 Answers1

0

So as you've probably figured out already, doing a type migration while keeping the old data intact is not currently possible (as far as I'm aware). So you'll have to work around that, one convoluted way I can think of is to create a field with your new type, and then on app start, iterate through all your current saves and use year.toDouble() and move any current values in the year to the yearDouble. (Sorry on phone so no real code)

Then when you need to pull that value again, check the original year value, if it's empty, then read the year value from your new yearDouble

You could also just ignore the original iteration all together and just do your check when you use that value. So modify your current method to check if yearDouble is empty, then read original year.toDouble(), and then add the value to the yearDouble property at the same time

Swisscheese
  • 571
  • 1
  • 5
  • 21