gpt4 book ai didi

android - Realm Kotlin 迁移 Android String

转载 作者:行者123 更新时间:2023-11-29 18:31:46 27 4
gpt4 key购买 nike

找不到答案。我正在尝试迁移 Realm 数据库。需要创建一个包含 2 个字段的 DBRequest 表:Int 和 String

if (oldVersion == 5L) {
val s = scheme.create("DBRequest")
s.addField("apiCode", Int::class.java)
}

没关系!但是如果我也尝试添加 String 类型

    s.addField("jsonRequest", String::class.java)

它抛出一个错误:

Caused by: io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the following errors: - Property 'DBRequest.jsonRequest' has been made required.

我不知道怎么解决。我试过这样的事情:

s.addField("jsonRequest", String::class.javaPrimitiveType!!)
-or-
s.addField("jsonRequest", String::class.javaObjectType)

没有任何帮助:(

最佳答案

将此添加到迁移

s
.addField("jsonRequest", String::class.java)
.setRequired("jsonRequest", true)

关于android - Realm Kotlin 迁移 Android String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55854376/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com