首页 > 解决方案 > FOREIGN KEY 约束失败(代码 787 SQLITE_CONSTRAINT_FOREIGNKEY)

问题描述

我不知道为什么在调用createBrowseRecord()函数时会出现此错误。我的代码如下,任何想法都将不胜感激。

 @Insert(onConflict = OnConflictStrategy.REPLACE)
     fun createBrowseRecord(br:BrowseRecord)

    @Entity(foreignKeys = [ForeignKey(entity = Composition::class,parentColumns =["id"],childColumns = ["compositionId"] ,onDelete = ForeignKey.CASCADE)])
    data class BrowseRecord(@PrimaryKey val compositionId:String, val browseTime:Long)

    @Entity
    data class Composition(
            val author: String,
            val commentAmount: Int,
            var cover: String,
            val description: String,
            val downloadURL: String,
            val backGround:String,
            val duration: String,
            @PrimaryKey  val id: String,
            var isLike: Boolean,
            val likeAmount: Int,
            val title: String
    )

标签: androidkotlinandroid-room

解决方案


推荐阅读