I am using realm 5.0.0
I want to add new table in existing data base how can i do that?
I have tried to find out solution but I found how to edit table but don't found how can i add new Table in realm in migration.
Realm.init(this);
RealmConfiguration config = new RealmConfiguration.Builder()
.name("myrealm.realm")
.schemaVersion(2)
.migration(new RealmMigration() {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
if (oldVersion == 0) {
RealmObjectSchema personSchema = realm.getSchema().get("SKUItem");
personSchema
.removeField("created_date")
.removeField("modification_date")
.addField("created_date", String.class)
.addField("modification_date", String.class)
;
} if (oldVersion == 1) {
// Here I want to add new Table
}
}
})
.build();
Realm.setDefaultConfiguration(config);
It would be something like this:
// Create a new class
schema.create("NewTable")
.addField("id", int.class, FieldAttribute.PRIMARY_KEY)
.addField("name", String.class, FieldAttribute.INDEXED);
olderVersion++;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments