Android Room: How to Migrate Column Renaming?

前端 未结 2 365
孤街浪徒
孤街浪徒 2021-01-11 14:42

Issue

My app is crashing because I am not handling migration properly. I\'m looking for a solution to migrate the name of 1 column in my table.

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-11 15:17

    There is a solution without migration - use ColumnInfo:

    data class Content(@PrimaryKey var id: String,  @ColumnInfo(name = "archiveCount") var dismissCount: Double) : Parcelable{...}
    

    Database column will be still archiveCount, but in Kotlin property will be renamed.

提交回复
热议问题