this is my code and I think it’s 100% correct
@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,
)
}
also, why tableName & autoGenerate
not showing in blue color
Because the code was working for me before, but now I don’t know why it doesn’t work now
2
Answers
I discovered the problem
userID: Int = 0
no 1remove default id you’ve set in constructor, leave it for fulfil by database (when it autogenerate id for you)
also remove your second constructor and keep all your variables as final (thus
val
, notvar
)edit: sample