2016-08-05 2 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을 사용하여 아래와 같이 정의 할 수 있습니다.

다음과 같이 응용 프로그램 클래스의 내부 영역의 응용 프로그램 인스턴스를 정의합니다

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을 지정하기 만하면됩니다.

관련 문제