当用户从1到3 db架构升级
时,我遇到异常Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{SplashActivity}: io.realm.exceptions.RealmMigrationNeededException: Realm on disk need to migrate from v1 to v3
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by io.realm.exceptions.RealmMigrationNeededException: Realm on disk need to migrate from v1 to v3
at io.realm.Realm.createAndValidateFromCache(Realm.java:389)
at io.realm.Realm.createInstance(Realm.java:364)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:346)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getDefaultInstance(Realm.java:273)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)**
领域配置如下:
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.name(AppConstants.DB_NAME)
.schemaVersion(schemaVersion)
.build();
try {
Realm.migrateRealm(realmConfiguration, new DBMigration()));
} catch (Exception ignored) {
// If the Realm file doesn't exist, just ignore.
}
Realm.setDefaultConfiguration(realmConfiguration);
我已在代码中指定了数据库迁移,其中我提到了所有数据库更改。
我正在使用领域版本3.3.0
您能帮忙解决这个问题吗? 提前谢谢。