我的Grails 3.0.9
应用程序中有多个域类,彼此之间有many-to-many
个关系。当我想从数据库中删除所有实体时,我收到错误消息:
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`))
这次是否有办法使用GORM
忽略外键约束?
我试图告诉域类中的GORM如下所示级联删除:
static mapping = {
figOtherTable cascade: 'all-delete-orphan'
}
就像在GORM docs中描述的一样,但这对我不起作用(或者我错过了一些东西)。
我已阅读here,您可以通过执行以下命令告诉MySQL忽略外键约束:
SET FOREIGN_KEY_CHECKS = 0
有没有办法用GORM做到这一点?