I’m trying to get ON_DELETE CASCADE working with SQLite.
I’ve set up the foreign keys properly, but when deleting the parent, the children stay.
I’ve read that SQLite defaults to
PRAGMA foreign_keys = OFF;
. I’ve tried setting that using:
Copy code
transaction {
exec("PRAGMA foreign_keys = ON;")
}
But still no luck. Any ideas?
pindab0ter
06/06/2019, 2:53 PM
Copy code
object Coops : IntIdTable() {
val name = text("name")
val contract = reference("contract_id", Contracts, CASCADE, NO_ACTION)
val hasStarted = bool("has-started").default(false)
init {
this.index(true, name, contract)
}
}
object CoopFarmers : Table() {
val farmer = reference("farmer", Farmers, CASCADE, NO_ACTION)
val coop = reference("coop", Coops, CASCADE, NO_ACTION)
init {
this.index(true, farmer, coop)
}
}
pindab0ter
06/06/2019, 3:08 PM
When testing in the SQLite CLI the propagation succeeds only after enabling that pragma. I can’t seem to get this to work in Exposed, however.