Timur Atakishiev
01/05/2020, 5:15 PMobject Users : Table("users") {
override val primaryKey = PrimaryKey(columns = *arrayOf(Column<Long>(Users, "id", LongColumnType())))
val id = long("id").autoIncrement()
val phoneNumber = varchar("phone_number", 20).uniqueIndex()
val firstName = varchar("first_name", 25).nullable()
val lastName = varchar("last_name", 30).nullable()
val password = varchar("password", 150)
}
can someone help please, when I overriding primary key as
override val primaryKey = PrimaryKey(columns = *arrayOf(id))
IDE says me that I need to initialize the ID field, maybe I am doing something wrong? Or is it other way to declare a Primary key?SackCastellon
01/06/2020, 9:42 AMprimaryKey
after you have declared the columns you are going to use as your primary key:
object Users : Table("users") {
val id = long("id").autoIncrement()
val phoneNumber = varchar("phone_number", 20).uniqueIndex()
val firstName = varchar("first_name", 25).nullable()
val lastName = varchar("last_name", 30).nullable()
val password = varchar("password", 150)
override val primaryKey = PrimaryKey(id)
}
I usually just put the primaryKey
at the end.Timur Atakishiev
01/06/2020, 10:14 AM