我有一個已經使用領域數據庫的應用程序。我現在想要添加一個新的RealmObject到模式中(比如我想添加Person
作爲我的新RealmObject類)。從文檔,它看起來像我需要做到以下幾點,以使這項工作:使用新架構遷移領域
RealmConfiguration config = new RealmConfiguration.Builder()
.schemaVersion(1) // Must be bumped when the schema changes
.migration(new MyMigration()) // Migration to run instead of throwing an exception
.build()
// Example migration adding a new class
class MyMigration extends RealmMigration {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
// DynamicRealm exposes an editable schema
RealmSchema schema = realm.getSchema();
// Migrate to version 1: Add a new class.
// Example:
// public Person extends RealmObject {
// private String name;
// private int age;
// // getters and setters left out for brevity
// }
if (oldVersion == 0) {
schema.create("Person")
.addField("name", String.class)
.addField("age", int.class);
oldVersion++;
}
etc....
這裏我的問題:我們真的需要創建Person
模式「手動」(即加場,與他們的類型) 這裏?或者是有使用Person
RealmObject因爲我們已經定義了一個方法哪些領域應該屬於新的類有
*我的問題在這裏:我們是否真的需要在這裏創建Person模式「手動」(即添加字段,使用它們的類型)嗎?*是 –
我想這對你有所幫助: https://medium.com/@ budioktaviyans/Android的境界,遷移架構4fcef6c61e82 – Yoni