Android – update domain database version

I use the realm of version 0.79.0 in the current Android project. Now, I want to update the domain version to 0.84.0. I also want to use realmconfiguration in the application class to use realm. Getdefaultinstance () instead of realm. GetInstance (context) for domain initialization

I implemented a new domain version and changed the necessary configuration. But when I ran my application, it crashed and displayed an error message

Thought I hadn't changed any model class

Who can tell me how to change the domain version through the default configuration of Android without any migration? If no migration is impossible, what will the migration class be like?

resolvent:

You need to migrate because we introduced null support in 0.83.0. You can learn more about how to migrate here: https://realm.io/news/realm-java-0.83.0/

However, you need to add a migration as follows:

RealmMigration migration = new RealmMigration() {
    @Override
    public long execute(Realm realm, long version) {
        Table table = realm.getTable(Dog.class);
        // Needed for all Strings
        table.convertColumnToNullable(table.getColumnIndex("name"));
        return 1;
    }
};

RealmConfiguration realmConfig = new RealmConfiguration.Builder(getContext())
    .schemaVersion(1)
    .migration(migration)
    .build();

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>