[英]How to use an existing database with an Android application using room ORM with Kotlin
[英]android, using Room with kotlin, how to add unique constrain on a field
per Annotate索引和唯一性 ,似乎可以像下面这样添加唯一性约束,
但在AndroidStudio 3中出现错误(编辑器带有红色下划线,表示“ unresolved the reference:indices”),:
/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,
使用Kotlin时如何在字段上添加唯一约束?
gradle就像:
buildscript {
ext {
verAndroidSupport = '27.0.0'
arch = "1.0.0"
archRoomVersion = "1.0.0"
}
ext.kotlin_version = '1.2.20'
和
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"
你错过了,
后"author"
@Entity(tableName = "author", indices = arrayOf(Index(value = "authorid", unique = true)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.