房间一对多外键异常-外键约束失败(代码787)

时间:2019-08-29 08:55:00

标签: exception kotlin foreign-keys one-to-many

使用“一对多房间”时,出现此异常(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>
) 

为什么会出现该异常?我该怎么办?

0 个答案:

没有答案