Everytime user update from play store, their data wiped out. I try to reproduce the problem by installing the previous version (2.1) through my pc, then update (2.2) at Play Store, but couldn't reproduce.
Can help me to figure out the real problem. Thanks :)
My setup as below:-
Android Studio Version : 3.1.2
Realm-gradle-plugin:4.3.0
TargetSdkVersion 28
CompileSdkVersion 28
BuildToolsVersion "28.0.3"
Realm.init(context);
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.name(Realm.DEFAULT_REALM_NAME)
.schemaVersion(0)
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(realmConfiguration);
You have set .deleteRealmIfMigrationNeeded(), so if people are upgrading from a version that is causing a migration, their Realm will be wiped. Generally, that setting should only be used during development.
deleteRealmIfMigrationNeeded() will delete your Realm if there is a new RealmObject class, or a RealmObject class is removed (I think), or a new field is added to a RealmObject class, or a field is removed from a RealmObject class, or you add a new field attribute to a field of a RealmObject class, or you remove a field attribute of a RealmObject class (@Index, @Required...)
This is expected behavior. If you don't want to lose data, write a migration. Please note that the schema must match perfectly between the two schema versions or you'll get a RealmMigrationNeededException.
Migrations are not triggered if you remove classes or properties from the schema again as the file is allowed to contain "extra" tables and properties, but otherwise 鈽濓笍 is correct.
(and generally, you probably want to actually remove classes/fields no longer used as part of the migration anyway to avoid confusion down the line).
Oh, that's new behavior that came in with the object store changes to "better suit sync", then.
I guess the part that was "I think" is outdated :smile:
I assume the above answered your question. If not feel free to re-open. Closing.