diff --git a/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt b/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt index f395b487d2..72a10ca447 100644 --- a/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt +++ b/src/main/kotlin/org/jetbrains/exposed/sql/ColumnType.kt @@ -283,6 +283,14 @@ open class VarCharColumnType(val colLength: Int = 255, collate: String? = null) append(" COLLATE $collate") } } + + override fun notNullValueToDB(value: Any): Any { + val string = super.notNullValueToDB(value) + require(string is String && string.length <= colLength) { + "Value '$string' can't be stored to database column because exceeds length $colLength" + } + return string + } } open class TextColumnType(collate: String? = null) : StringColumnType(collate) {