JetBrains / JetBrains/Exposed

"NULL in non-nullable column" error should include the offending table and column name

Open
#1,268 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
9.3k
Forks
798
Avg merge
4d 2h
Merged PRs (30d)
26

Description

exposed-core:0.31.1

```
java.lang.IllegalStateException: NULL in non-nullable column
at org.jetbrains.exposed.sql.IColumnType$DefaultImpls.valueToString(ColumnType.kt:48)
at org.jetbrains.exposed.sql.ColumnType.valueToString(ColumnType.kt:74)
at org.jetbrains.exposed.sql.QueryBuilder$registerArguments$1.invoke(Expression.kt:69)
at org.jetbrains.exposed.sql.QueryBuilder.registerArguments(Expression.kt:72)
at org.jetbrains.exposed.sql.QueryBuilder.registerArgument(Expression.kt:63)
at org.jetbrains.exposed.sql.QueryBuilder.registerArgument(Expression.kt:58)
at org.jetbrains.exposed.sql.statements.UpdateStatement.arguments(UpdateStatement.kt:26)
at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_core(Statement.kt:31)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:129)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:115)
at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:28)
at org.jetbrains.exposed.sql.QueriesKt.update(Queries.kt:178)
at org.jetbrains.exposed.sql.QueriesKt.update$default(Queries.kt:175)
```

Please add the relevant context information so users could tell what was wrong with the code.

In my case, the error was caused by `val refId = reference(...)` instead of `val refId = optReference(...)`.
The actual DB model was "optional foreign key", so the proper API should be `optReference`.

However, the strange thing is `reference(..)` field accepts nulls, and `optReference(..)` rejects null in `update` and `insert`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.