Mohammad Jaber
06/30/2023, 8:46 PMobject Users : IdTable<UUID>() {
override val id = uuid("user_id").entityId()
val name = varchar("name", 255)
val email = varchar("email", 255).uniqueIndex()
val passwordHash = varchar("password_hash", 60)
}
object RefreshTokens: IdTable<UUID>() {
override val id = uuid("refresh_token_id").entityId()
val userId = reference("user_id", Users).uniqueIndex()
val token = varchar("token", 255)
val expiresAt = datetime("expires_at")
}
I'm trying to create a relationship between Users
and RefreshTokens
tables with user_id
being a foreign key in RefreshTokens
table.
However, when I try to run my application, I get this error:
ERROR: there is no unique constraint matching given keys for referenced table "users"
From what I understand, user_id
in Users
is a primary key and it should be unique, but I'm not sure why I'm getting this error.
I've also posted this question on StackOverflow.
Any insights would be greatly appreciated. Thank you!Casey Brooks
07/01/2023, 12:18 AMMohammad Jaber
07/01/2023, 3:28 AMZachary Siegel
07/01/2023, 3:35 PMval userId = reference("user_id", Users.id).uniqueIndex()