Skip to content
New issue

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

SchemaUtils.createMissingTablesAndColumns problem on H2 table with primary key #841

Closed
supertote opened this issue Mar 19, 2020 · 3 comments
Labels

Comments

@supertote
Copy link

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.

@hiperbou
Copy link

hiperbou commented Jun 2, 2020

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)
        }
    }

@supertote
Copy link
Author

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

Tapac added a commit that referenced this issue Sep 18, 2020
…imary key #841

Using PrimaryKey fails with h2.Database #1051
@Tapac
Copy link
Contributor

Tapac commented Apr 5, 2021

Fixed in #1051 (Released in Exposed 0.27.1)

@Tapac Tapac closed this as completed Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants