I have multiple domain classes in my Grails 3.0.9
application which have many-to-many
relations to each other. When I want to delete all entities from the database I get an error saying:
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not execute statement; SQL [n/a]; Cannot delete or update a parent row: a foreign key constraint fails (`database`.`figure`, CONSTRAINT `FK_dbgwxhc7ggggypvmf967wvgfw` FOREIGN KEY (`fig_other_table_id`) REFERENCES `other_table` (`id`)); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`database`.`figure`, CONSTRAINT `FK_dbgwxhc7ggggypvmf967wvgfw` FOREIGN KEY (`fig_other_table_id`) REFERENCES `other_table` (`id`))
Is there a way using GORM
to ignore foreign key contraints this time?
I've tried to tell GORM in the domain class to cascade delete like this:
static mapping = {
figOtherTable cascade: 'all-delete-orphan'
}
like descriped in the GORM docs, but that's not working for me (or I am missing something).
I've read here that you can tell MySQL to ignore foreign key constraints by executing:
SET FOREIGN_KEY_CHECKS = 0
Is there a way doing this with GORM?