We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Kotlin 1.6.10 and Exposed 0.37.3
When setting a default value for an enum column and using SchemaUtils.create, Exposed uses toString() instead of the toDb method.
SchemaUtils.create
toString()
toDb
Here's as small an example as I could come up with to recreate the issue:
object MyTable : LongIdTable(name = "my_table", columnName = "id") { val myEnum: Column<MyEnum> = customEnumeration( name = "my_enum", sql = "ENUM('${MyEnum.DEFAULT.dbString}')", fromDb = { MyEnum.values().first { e -> e.dbString == (it as String) } }, toDb = { it.dbString }, // <-- this and the line below are the relevant parts ).default(MyEnum.DEFAULT) } enum class MyEnum(val dbString: String) { DEFAULT("the default value"); override fun toString() = "the wrong string!" } fun main() { Database.connect( url = "jdbc:mysql://localhost:3306/test", driver = com.mysql.cj.jdbc.Driver::class.qualifiedName!!, user = "username", password = "password") transaction { SchemaUtils.create(MyTable) } }
This will generate the following SQL:
CREATE TABLE IF NOT EXISTS my_table (id BIGINT AUTO_INCREMENT PRIMARY KEY, my_enum ENUM('the default value') DEFAULT 'the wrong string!' NOT NULL)
which throws the following exception:
org.jetbrains.exposed.exceptions.ExposedSQLException: java.sql.SQLSyntaxErrorException: Invalid default value for 'my_enum'
The text was updated successfully, but these errors were encountered:
SchemaUtils.create doesn't use enum column's 'toDb' function #1475
fc8775e
Released in 0.38.1
Sorry, something went wrong.
No branches or pull requests
Using Kotlin 1.6.10 and Exposed 0.37.3
When setting a default value for an enum column and using
SchemaUtils.create
, Exposed usestoString()
instead of thetoDb
method.Here's as small an example as I could come up with to recreate the issue:
This will generate the following SQL:
which throws the following exception:
The text was updated successfully, but these errors were encountered: