3
レルムフィールドのデータ型をString
からint
に変更したいのですが、このフィールドもPrimary Key
です。私はRealmMigration
でこの問題を解決する方法を見つけることができませんでした。レルムフィールドのデータ型を変更する - Java
PS:私のアプリはすでに制作中で、そのフィールドに現在あるすべての値は整数です。
EDIT 1
マイModelクラス
public class Team extends RealmObject {
@SerializedName("id")
@PrimaryKey
private int id;
@SerializedName("name")
private String name;
@SerializedName("description")
private String description;
}
私の移行がありワンライナー方式ではありませんが、あなたは従うことができます
if (oldVersion == 6) {
RealmObjectSchema teamSchema = schema.get("Team");
teamSchema.addField("temp_id", int.class)
.transform(new RealmObjectSchema.Function() {
@Override
public void apply(DynamicRealmObject obj) {
obj.setInt("temp_id", Integer.valueOf(obj.getString("id")));
}
})
.removeField("id")
.renameField("temp_id", "id")
.addPrimaryKey("id");
}
'removePield'を使用しているときに' removePrimaryKey'が暗黙的に適用されていますか? –
古い列と新しい列の名前を同じにしたいと思います...可能ですか? –
@Timはい、それは1.0.1で修正されたバグでした。https://github.com/realm/realm-java/blob/master/CHANGELOG.md –