値が、これは容易ではないと、私は知らないなぜレルムの移行重複は私が前に他の人がやったの移行(レルム87.2)をやりたい
私previsoly Categoriy.class
private int code;
private String title;
private String category;
private int order;
private boolean visible;
@PrimaryKey @Index private String id;
private int code;
private String title;
private String category;
private int order;
private boolean visible;
とMigration.class
で新しいCategory.classいくつかのダムの理由で0public class Migration....
int i = 0;
.....
if(oldVersion == 7) {
schema.get("Category").addField("id", String.class, FieldAttribute.PRIMARY_KEY).transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject obj) {
obj.set("id", UtilsForAll.getRandomUUID()); //Get Random UUID for previsoly added categories
obj.set("order", i);
i++;
}
});
oldVersion++;
}
} //finishClass
と私はイムが間違っているのか知っている、それは私にこのエラーを与えておくいけない:
java.lang.IllegalArgumentException: Illegal Argument: Field "id" cannot be a primary key, it already contains duplicate values:
WHAT?カテゴリーのクラスに重複した値はありません。
PSは:これはちょうど私が実際に移行を使用するときに発生し、HAS PREVIOSLY CATEGORYのRECORDS
--------------------- EDIT 22/03
Emanuelez`s提案として、この試み:
if(oldVersion == 7) {
schema.get("Category").addField("id", String.class);
schema.get("Category").transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject obj) {
obj.set("id", UtilsForAll.getRandomUUID()); //Get Random UUID for previsoly added categories
}
});
oldVersion++;
schema.get("Category").setPrimaryKey("id");
}
をエラーはこの1つになって -
io.realm.exceptions.RealmMigrationNeededException: Field 'id' does support null values in the existing Realm file. Remove @Required or @PrimaryKey from field 'id' or migrate using io.realm.internal.Table.convertColumnToNotNullable().
iがve tried
.setNullable(「ID」、真の); `
何もすべて、これらのフィールドをデフォルト値に初期化されますので、あなただけの属性を持つフィールドを追加することはできません新しいプライマリキーフィールドを追加するにはあまりにも
この3つのステップを試してみましたが、何も変更されていません。ただエラーです。あなたが私に指摘したテストとまったく同じことを行っていると思います=( – user2582318
私はまだこの問題に直面しています。 – AndoAiron