线程 "main" org.postgresql.util.PSQLException 中的 Kotlin 异常:错误

Kotlin Exception in thread "main" org.postgresql.util.PSQLException: ERROR

我在 Web 应用程序中使用 Kotlin Exposed for ORM。 我有一个实体用户,它是在数据库中创建的(PostgreSQL) 当我想在 table(User) 中查找值时遇到问题,请显示此错误

Exception in thread "main" org.postgresql.util.PSQLException: ERROR: column users.emailSituation does not exist Hint: Perhaps you meant to reference the column "users.emailsituation". Position: 59

我的数据库是 postgresql

用户实体:

object Users : IntIdTable() {
    val name = text("name").index()
    val family = text("family").index()
    val email = text("email").index()
    val emailSituation = bool("emailSituation")
    val mobile = long("mobile").index()
}

class User(id: EntityID<Int>) : IntEntity(id) {
    companion object : IntEntityClass<User>(Users)

    var name by Users.name
    var family by Users.family
    var email by Users.email
    var emailSituation by Users.emailSituation
    var mobile by Users.mobile
}

找到一个值:

transaction {
        logger.addLogger(StdOutSqlLogger)
 println("User: ${User.find { Users.mobile eq 87654 }.joinToString {it.name}}")
    }

我该如何解决?

错误似乎表明它正在尝试查询名为 emailSituation 的列,但只有 emailsitutation 可用。这可能与您的图书馆最终构建查询的方式有关。 Postgres will generally accept anything and lowercase it for column names unless you quote it(这可能是您无法控制的)。要解决此问题,请尝试将映射到的列的名称小写:

变化:

val emailSituation = bool("emailSituation")

收件人:

val emailSituation = bool("emailsituation")
                                ^
                                +-- That's the difference