使用“一对多房间”时,出现此异常(FOREIGN KEY约束失败(代码787))。这是我的课程:
主要模型(包裹):
@TypeConverters(Converters::class)
@Entity(tableName = "parcels")
data class Parcel(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "parcel_key")
var parcelKey: Long,
@Embedded
var type: ParcelType?,
(...)
)
子模型(文档):
@Entity(
tableName = "documents",
indices = [Index(value = ["linked_parcel_key"])],
foreignKeys = [ForeignKey(
entity = Parcel::class,
parentColumns = arrayOf("parcel_key"),
childColumns = arrayOf("linked_parcel_key"),
onDelete = CASCADE
)]
)
data class Document(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "document_key")
val documentKey: Long,
@ColumnInfo(name = "linked_parcel_key")
var parcelKey: Long,
val title: String,
(...)
)
这是我的ParcelWithDocuments类:
data class ParcelWithDocuments(
@Embedded
val parcel: Parcel,
@Relation(
parentColumn = "parcel_key",
entityColumn = "linked_parcel_key"
)
var docs: List<Document>
)
为什么会出现该异常?我该怎么办?