Hi all ```object Users : Table("users") { over...
# exposed
t
Hi all
Copy code
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
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)
}
I usually just put the
primaryKey
at the end.
👍 1
t
Okay, thank you, I will try