https://kotlinlang.org logo
#exposed
Title
# exposed
r

Renaud

02/02/2022, 6:26 PM
I have a micro-service in Ktor and I wanted to add a new column (attribute) in a Table. Let’s call this attribute
given_name
. Using Flyway, I’ve successfully added this new attribute to my table (I can see it using a DB file explorer) and I have added the following line :
Copy code
object MyTable : ExtendedUUIDTable("whateverTable") {
    ...
    val givenName: Column<String> = text("given_name")
}
When I try to use this field, I get the following exception :
Copy code
java.lang.IllegalStateException: com.innovorder.server.data.model.WhateverTable.given_name is not initialized yet
I found that Exposed is missing some wiki pages regarding doing DB migration. Did someone run into this error as well?
p

Phil Richardson

02/03/2022, 4:45 PM
Did your migration initialise values to the new column, or are the rows returning
null
for this this due to the lack of initialization? If they are
null
as I suspect could be the case, you have a two options. 1: Make the column
nullable
in your Table object, i.e.
val givenName: Column<String> = text("given_name").nullable()
2: Leave the column as not nullable, but have a client side default
val givenName: Column<String> = text("given_name").clientDefault("")
r

Renaud

02/04/2022, 9:11 AM
I put the column as nullable and it solved my problem 👍 Thanks Phil !
3 Views