object 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
Copy code
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?
s
SackCastellon
01/06/2020, 9:42 AM
You need to override the
primaryKey
after you have declared the columns you are going to use as your primary key:
Copy code
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)
}