How to annotate a default value inside a android room entity?

With the release of room persistence 2.2.0, there’s a new property added to @ColumnInfo annotation which can be used to specify the default value of a column. See documentation.

@Entity(tableName = "users")
data class User(
    @PrimaryKey val id: Long,
    @ColumnInfo(name = "user_name", defaultValue = "temp") val name: String
    @ColumnInfo(name = "last_modified", defaultValue = "CURRENT_TIMESTAMP" ) val lastModified: String
)

Leave a Comment