是的,應用程序會崩潰。您需要添加一個RealmMigration類。
public class CustomMigration implements RealmMigration {
@Override
public long migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
if (oldVersion == 0) {
// Migrate from v0 to v1
schema.create("myNewTable"); // example
oldVersion++;
}
if (oldVersion == 1) {
// Migrate from v1 to v2
oldVersion++;
}
if (oldVersion < newVersion) {
throw new IllegalStateException(String.format(Locale.US, "Migration missing from v%d to v%d", oldVersion, newVersion));
}
}
}
和
RealmConfiguration config = new RealmConfiguration.Builder(context)
.schemaVersion(2)
.migration(new MyMigration())
.build();
Realm.setDefaultConfiguration(config);
// This will automatically trigger the migration if needed
Realm realm = Realm.getDefaultInstance();
'將在應用程序崩潰?''是如果是這樣,有什麼辦法解決呢?'要麼設置deleteIfMigrationNeeded(),或添加遷移。 – EpicPandaForce