领域迁移。如何更改列表类型?

时间:2021-04-08 17:18:47

标签: android kotlin migration realm

在我的应用中,我有这门课

open class LocalIds(
    @PrimaryKey var id: Int = 0,
    @Required var list: RealmList<Int> = RealmList()
) : RealmObject()

我需要将其转换为

open class LocalIds(
    @PrimaryKey var id: Int = 0,
    var list: RealmList<FavoriteId> = RealmList()
) : RealmObject()

FavoriteId 在哪里

open class FavoriteId(
    var postId: Int = 0,
    var folderId: Int? = null
): RealmObject()

但我没有在任何地方找到有关如何更改列表类型(仅限列表字段)的信息。

这样就够了

val localIdsSchema = schema[LocalIds::class.java.simpleName]
localIdsSchema.removeField("list")
localIdsSchema.addRealmListField("list", favoriteIdScheme)

还是我应该做点别的?你能帮我分享一些例子吗?

附言错误

io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the following errors:
    - Property 'LocalIds.list' has been changed from 'array<int>' to 'array<FavoriteId>'.

0 个答案:

没有答案