You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have what I thought to be a simple schema, but createMissingTablesAndColumns() throught an exception when executing.
Schema
object Connections : IntIdTable() {
val fromStation = reference("fromStation", Stations)
val toStation = reference("toStation", Stations)
val minDuration = integer("minDuration")
val medianDuration = integer("medianDuration")
val lastDownload = long("lastDownload")
init {
uniqueIndex(fromStation, toStation)
}
}
object Stations : IdTable<String>() {
overrideval id = varchar("id", 9).uniqueIndex().entityId()
val name = varchar("name", 100)
val latitude = double("latitude")
val longitude = double("longitude")
val type = varchar("type", 100).nullable()
overrideval primaryKey =PrimaryKey(id)
}
My call:
val config =HikariConfig().apply {
// .... using Postgresql
}
val dataSource =HikariDataSource(config)
Database.connect(dataSource)
transaction {
addLogger(StdOutSqlLogger)
SchemaUtils.createMissingTablesAndColumns(Connections, Stations)
}
Log:
SQL: CREATE TABLE IF NOT EXISTS stations (id VARCHAR(9) PRIMARY KEY, "name" VARCHAR(100) NOT NULL, latitude DOUBLE PRECISION NOT NULL, longitude DOUBLE PRECISION NOT NULL, "type" VARCHAR(100) NULL)
SQL: ALTER TABLE stations ADD CONSTRAINT stations_id_unique UNIQUE (id)
SQL: CREATE TABLE IF NOT EXISTS connections (id SERIAL PRIMARY KEY, "fromStation" VARCHAR(9) NOT NULL, "toStation" VARCHAR(9) NOT NULL, "minDuration" INT NOT NULL, "medianDuration" INT NOT NULL, "lastDownload" BIGINT NOT NULL, CONSTRAINT fk_connections_fromstation_id FOREIGN KEY ("fromStation") REFERENCES stations(id) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT fk_connections_tostation_id FOREIGN KEY ("toStation") REFERENCES stations(id) ON DELETE RESTRICT ON UPDATE RESTRICT)
SQL: ALTER TABLE connections ADD CONSTRAINT connections_fromstation_tostation_unique UNIQUE ("fromStation", "toStation")
SQL: ALTER TABLE connections ADD CONSTRAINT fk_connections_fromstation_id FOREIGN KEY ("fromStation") REFERENCES stations(id) ON DELETE RESTRICT ON UPDATE RESTRICT
SQL: ALTER TABLE connections ADD CONSTRAINT fk_connections_fromstation_id FOREIGN KEY ("fromStation") REFERENCES stations(id) ON DELETE RESTRICT ON UPDATE RESTRICT
SQL: ALTER TABLE connections ADD CONSTRAINT fk_connections_fromstation_id FOREIGN KEY ("fromStation") REFERENCES stations(id) ON DELETE RESTRICT ON UPDATE RESTRICT
Exception in thread "main" org.jetbrains.exposed.exceptions.ExposedSQLException: org.postgresql.util.PSQLException: ERROR: constraint "fk_connections_fromstation_id" for relation "connections" already exists
SQL: [ALTER TABLE connections ADD CONSTRAINT fk_connections_fromstation_id FOREIGN KEY ("fromStation") REFERENCES stations(id) ON DELETE RESTRICT ON UPDATE RESTRICT]
at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_core(Statement.kt:63)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:126)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:112)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:88)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:79)
at org.jetbrains.exposed.sql.SchemaUtils.execStatements(SchemaUtils.kt:174)
at org.jetbrains.exposed.sql.SchemaUtils.createMissingTablesAndColumns(SchemaUtils.kt:243)
at org.jetbrains.exposed.sql.SchemaUtils.createMissingTablesAndColumns$default(SchemaUtils.kt:228)
At first I though it was due to the uniqueIndex not working, but when I disable it it still fails.
It looks like it is trying to add the constraints multiple time.
The text was updated successfully, but these errors were encountered:
I have what I thought to be a simple schema, but
createMissingTablesAndColumns()
throught an exception when executing.Schema
My call:
Log:
At first I though it was due to the
uniqueIndex
not working, but when I disable it it still fails.It looks like it is trying to add the constraints multiple time.
The text was updated successfully, but these errors were encountered: