Exposed: SchemaUtils.createMissingTablesAndColumns problem on H2 table with primary key

Created on 19 Mar 2020  路  3Comments  路  Source: JetBrains/Exposed

Hi,

After migrating from Exposed 0.17.3 to Exposed 0.22.1 we are facing an error when using SchemaUtil.createMissingTablesAndColumns with an H2 database on a table with primary key.

The eror produced is:
Syntax error in SQL statement "ALTER TABLE USERS MODIFY COLUMN ID VARCHAR(50) PRIMARY[*] KEY"

Checking the H2 documentation states that:
The options PRIMARY KEY, UNIQUE, and CHECK are not supported for ALTER statements

Which explains the error.

bug h2

All 3 comments

Did you find a solution, @supertote ?

The fun thing is, if you change the name of the table to anything different than Users or the "id" to "id2" it will work as expected.

Using h2 1.4.200 and exposed 0.25.1

This code will throw an exception.

```
object Users : Table() {
val id = integer("id") //change "id" to "id2" to pass the test :)
override val primaryKey = PrimaryKey(id)
}

@Test
fun h2UsersTableTest() {
    Database.connect("jdbc:h2:mem:test", "org.h2.Driver")

    transaction {
        addLogger(StdOutSqlLogger)
        create(Users)
        createMissingTablesAndColumns(Users)
    }
}

Sorry @hiperbou but I don't have a solution to this problem.

Fixed in #1051 (Released in Exposed 0.27.1)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

power721 picture power721  路  3Comments

hannesstruss picture hannesstruss  路  5Comments

x3ro picture x3ro  路  5Comments

fmgonsalves picture fmgonsalves  路  3Comments

barry-m picture barry-m  路  3Comments