Error when deleting content item and references

Description

Error occured when I deleted content items from the DB:
$this->getContentRepo()>deleteReference($deleteItem>getId());
$this->getDocumentManager()->remove($deleteItem);

If I first remove the content item and then the references the error does not occur.

[Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException]
An exception occurred while executing 'DELETE FROM workflow_states WHERE id = ?' with params [8838]:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`devjohandzg`.`workflow_history`, CONSTRAINT `FK_25F6E6FB7E3C61F9` FOREIGN KEY (`owner_id`) REFERENCES `work
flow_states` (`id`))

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`devjohandzg`.`workflow_history`, CONSTRAINT `FK_25F6E6FB7E3C61F9` FOREIGN KEY (`owner_id`) REFERENCES `work
flow_states` (`id`))

[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`devjohandzg`.`workflow_history`, CONSTRAINT `FK_25F6E6FB7E3C61F9` FOREIGN KEY (`owner_id`) REFERENCES `work
flow_states` (`id`))

 

 

Oplossing:

ALTER TABLE workflow_history DROP FOREIGN KEY FK_25F6E6FB5D83CC1;
ALTER TABLE workflow_history ADD CONSTRAINT FK_25F6E6FB5D83CC1 FOREIGN KEY (state_id) REFERENCES workflow_definition_states(id) ON DELETE CASCADE ON UPDATE RESTRICT;
ALTER TABLE workflow_history DROP FOREIGN KEY FK_25F6E6FB7E3C61F9; ALTER TABLE workflow_history ADD CONSTRAINT FK_25F6E6FB7E3C61F9 FOREIGN KEY (owner_id) REFERENCES workflow_states(id) ON DELETE CASCADE ON UPDATE RESTRICT;

Deployment actions

None

Technical tasks

None

Assignee

Marijn Otte

Client

Marijn Otte

External issue ID

None

Min. hours

None

Dev hour estimate

None

Affects versions