0
我想使用Realm migration
來維護僅一個表的數據。像這裏一樣,我想維護Profile User
表的數據並刪除表中的所有其餘部分。僅維護特定表的域數據遷移
這是我迄今爲止所做的。但數據庫中的所有內容都會被刪除。
initRealm()
會從onCreate()
的配置類
private class RealmMigrationClass implements RealmMigration {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
if (oldVersion == 2) {
RealmObjectSchema profileUserSchema = schema.get("ProfileUser");
profileUserSchema.addField("test", String.class);
oldVersion++;
}
}
}
如果要遷移,你可能不應指定'.deleteRealmIfMigrationNeeded()':P – EpicPandaForce
是啊,兄弟,我知道,但我將如何解決這種情況。 – viper
刪除'.deleteIfMigrationNeeded()'? – EpicPandaForce