2016-08-05 6 views
1

アンドロイドにはレルムバージョン0.86があります。私は1.1.1にアップグレードしようとしましたが、その後、私は領域の移行が必要だと言ってエラーを投げました。誰かがあるバージョンから別のバージョンに移行する方法を知っていますか?実装が簡単な、より安全なバージョンがありますか?おかげレルムの新しいバージョンに移行しますか?

答えて

0

私たちは、あなたが始めるために使用することができ、ここで移行例があります:https://github.com/realm/realm-java/blob/master/examples/migrationExample/src/main/java/io/realm/examples/realmmigrationexample/model/Migration.java

移行は、一般的にここに記載されています:https://realm.io/docs/java/latest/#migrations

あなたはとしてレルムを使用するユースケースのための簡単な解決策ネットワーク要求に対するキャッシュ機構。ちょうどあなたのRealmConfigurationにdeleteRealmIfMigrationNeeded()を追加:https://realm.io/docs/java/latest/api/io/realm/RealmConfiguration.Builder.html#deleteRealmIfMigrationNeeded--

0

あなたは私たちは、デフォルトでは、我々は移行エラーを得たアプリを実行する場合は、この 任意の旧バージョンから1.0.0+する新しいバージョンにあなたのレルムDBをアップグレードする場合。しかし、以下のようにMigrationを定義することでこれを解決することができます。

次のようにApplicationクラス内のレルムアプリのインスタンスを定義します。

public class MainApplication extends Application { 
@Override 
public void onCreate() { 
    super.onCreate(); 
    Fabric.with(this, new Crashlytics()); 

    VolleyHelper.init(this); 

    // The Realm file will be located in Context.getFilesDir() with name "default.realm" 
    RealmConfiguration config = new RealmConfiguration.Builder(this) 
      .schemaVersion(1) 
      .migration(new MyMigration()) 
      .build(); 
    Realm.setDefaultConfiguration(config); 
}} 

を使用すると、データベース構造の変更を行うだけレルムのバージョンをアップグレードしない場合、以下のようにマイグレーションクラスを定義します。データベース構造の変更を行う場合は、MyMigrationクラスの下でそれを定義する必要があります。あなたはここからより多くの移行情報を取得することができますRealm Migration

public class MyMigration implements RealmMigration { 
@Override 
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { 

}} 
+0

「@ PrimaryKey」が0.89.0でnullableになったため、彼は移行する必要があります – EpicPandaForce

0

その他は、すでに例の移行とthe docsをリンクしているので、私はちょうどあなたがだからもしbreaking change in 0.89.0

@PrimaryKey field value can now be null for String, Byte, Short, Integer, and Long types. 
Older Realms should be migrated, using RealmObjectSchema.setNullable(), 
or by adding the @Required annotation. (#2515). 

に実行していることを教えましょうこの場合に移行を使用しないようにするには、@PrimaryKeyフィールドに@Requiredを指定するだけです。

関連する問題