小编Nav*_*jan的帖子

如何将非空表列迁移到 Android Room 数据库中的 Null

我是 android 房间图书馆的新手。我需要将 Not Null 列迁移到 Null,但房间迁移只允许在 ALTER 表查询中添加或重命名。如何执行列迁移查询?

@Entity(tableName = "vehicle_detail")
data class VehicleDetailsEntity(
    @PrimaryKey(autoGenerate = true)
    val vehicleClientId: Long = 0,
    val vehicleId: String,
    val updatedOn: Date,
    val updatedBy: String
)
Run Code Online (Sandbox Code Playgroud)

我需要将表结构更改为

@Entity(tableName = "vehicle_detail")
data class VehicleDetailsEntity(
    @PrimaryKey(autoGenerate = true)
    val vehicleClientId: Long = 0,
    val vehicleId: String,
    val updatedOn: Date?,
    val updatedBy: String?
)
Run Code Online (Sandbox Code Playgroud)

java.lang.IllegalStateException: Room 无法验证数据完整性。看起来您已更改架构但忘记更新版本号。您可以通过增加版本号来简单地解决此问题。

android kotlin android-room androidx

4
推荐指数
1
解决办法
2762
查看次数

标签 统计

android ×1

android-room ×1

androidx ×1

kotlin ×1