lan*_*nyf 1 unique-constraint kotlin android-room
每个Annotate索引和唯一性,似乎它可以添加如下所示的唯一约束,
但在AndroidStudio 3中出现错误(编辑器有红色下划线表示"未解析参考:索引"),:
/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,
Run Code Online (Sandbox Code Playgroud)
如何在使用kotlin时在字段上添加唯一约束?
gradle就像:
buildscript {
ext {
verAndroidSupport = '27.0.0'
arch = "1.0.0"
archRoomVersion = "1.0.0"
}
ext.kotlin_version = '1.2.20'
Run Code Online (Sandbox Code Playgroud)
和
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
//arch
implementation "android.arch.lifecycle:runtime:${arch}"
implementation "android.arch.lifecycle:extensions:${arch}"
annotationProcessor "android.arch.lifecycle:compiler:${arch}"
//room
compile "android.arch.persistence.room:runtime:${archRoomVersion}"
annotationProcessor "android.arch.lifecycle:compiler:${arch}"
annotationProcessor "android.arch.persistence.room:compiler:${archRoomVersion}"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha1"
Run Code Online (Sandbox Code Playgroud)
你错过了,后"author"
@Entity(tableName = "author", indices = arrayOf(Index(value = "authorid", unique = true)))
| 归档时间: |
|
| 查看次数: |
1904 次 |
| 最近记录: |