这是我代码,我认为它100%正确
@Serializable
@Entity(tableName = "user_table")
data class User(
@PrimaryKey(autoGenerate = true)
var userID: Int = 1,
var fullName: String = "Missing",
var email: String = "Missing",
var password: String = "Missing",
var phone: Long = -1,
var profileImage: String = "Missing",
var userType: Int = -1,
) {
constructor(
userID: Int = 1
) : this(
fullName = "Missing",
email = "Missing",
password = "Missing",
phone = -1,
profileImage = "Missing",
userType = -1,
)
}
还有,为什么tableName & autoGenerate
没有显示为蓝色
因为代码以前对我有效,但现在不知道为什么不起作用了
2条答案
按热度按时间7gcisfzg1#
删除您在构造函数中设置默认id,让它由数据库实现(当它为您自动生成id时)
同时删除第二个构造函数,并将所有变量保留为final(因此是
val
,而不是var
)编辑:示例
nvbavucw2#
我发现了问题
userID: Int = 0
编号1