我想在两个表之间建立关系,这样做时遇到问题。
我的第一个实体是:
@Entity(tableName = "rooms_table")
data class RoomsEntity(
@PrimaryKey
val room_id: Int,
val room_name: String,
val last_message: String,
val room_image: String,
val last_date: Date?,
val new_counter: Int
) {
constructor() : this(0, "","", "", null,0)
}
第二个实体是:
@Entity(
tableName = "subscribers_table",
foreignKeys = [ForeignKey(
entity = RoomsEntity::class,
parentColumns = arrayOf("subscriber_id"),
childColumns = arrayOf ("room_id"),
onDelete = ForeignKey.CASCADE
) ]
)
data class SubscribersEntity(
@PrimaryKey
val subscriber_id: Int,
val room_id: Int,
val subscriber_name: String,
val subscriber_image: String
) {
constructor() : this(0, 0, "", "")
}
构建项目时出现此错误:
"room_id column references a foreign key but it is not part of an index. This may trigger full table scans whenever parent table is modified so you are highly advised to create an index that covers this column."