Search code examples
mysqlktorkotlin-exposed

Jetbrains Exposed generating duplicate foreign keys


I have this table schema:

object ValuesTable : IntIdTable("values") {
    val parameter =
        reference("parameters", ParametersTable, onDelete = ReferenceOption.CASCADE, onUpdate = ReferenceOption.CASCADE)
    val service =
        reference("services", ServicesTable, onDelete = ReferenceOption.CASCADE, onUpdate = ReferenceOption.CASCADE)
    val values = text("actual_values")
}

When exposed tries to create my table i'm getting `java.sql.SQLException: Duplicate foreign key constraint name 'fk_values_parameters_id'. I've tried manually adding a different fkName, also tried to use a different table name starting with uppercase.

MySQL version is : Ver 8.0.19 for macos10.15 on x86_64 (MySQL Community Server - GPL)


Solution

  • The problem seems to be caused SchemaUtils.createMissingTablesAndColumns(). Using simply SchemaUtils.create() works as expected