android,使用带kotlin的Room,如何在字段上添加唯一约束

时间:2018-02-11 20:10:27

标签: kotlin unique-constraint android-room

Annotate indices and uniqueness,似乎可以添加如下所示的唯一约束,

但在AndroidStudio 3中出现错误(编辑器有红色下划线表示“未解析参考:索引”),:

.navbar-light .navbar-nav .nav-link {
    color: red;
}

如何在使用kotlin时在字段上添加唯一约束?

gradle就像:

/Users/application/database/DbAuthor.kt
Error:(14, 39) Expecting an element

@Entity(tableName = "author" indices = arrayOf(Index(value = "authorid", unique = true)))
class DbAuthor(

    @ColumnInfo(name = "authorid")
    var authorid: Int? = null,

buildscript {
ext {
    verAndroidSupport = '27.0.0'
    arch = "1.0.0"
    archRoomVersion = "1.0.0"

}
ext.kotlin_version = '1.2.20'

1 个答案:

答案 0 :(得分:8)

,后你错过了"author" @Entity(tableName = "author", indices = arrayOf(Index(value = "authorid", unique = true)))