3
두 엔티티 - Background
및 Action
이 있습니다. a Background
에는 많은 Actions
이 있습니다. symfony2 : 삭제시 연결 해제
내가Action
하지만 널 외래 키를 유지 에 원하는 Background
을 삭제
SQLSTATE[23000]: Integrity constraint violation:
1451 Cannot delete or update a parent row:
a foreign key constraint fails (`Action`, CONSTRAINT
`FK_B7722E25C93D69EA` FOREIGN KEY (`background_id`)
REFERENCES `Background` (`id`))
현재로서는 해결 방법은 관련 작업을 반복하고 필드를 null로 유지하는 것입니다. 이것이 앞으로 나아갈 수있는 최선의 방법은 아닙니다.
foreach ($background->getActions() as $action) {
$action->setBackground(null);
}
그냥 삭제 설정 널 (null)에 대한 데이터베이스 수준에서 제약 조건을 변경하는 데 도움이, 당신은 돈 ' 귀하의 응용 프로그램 코드를 사용하여 데이터베이스 작업을 수행 할 필요가 없습니다. 여기에 주석을 사용하는 또 다른 방법이 있습니다. [* Doctrine 2 OneToMany Cascade SET NULL *] (http://stackoverflow.com/questions/8858645/doctrine-2-onetomany-cascade- set-null) –
가능하면 다음과 중복됩니다. http://stackoverflow.com/questions/12471715/how-exactly-to-use-ondelete-set-null-doctrine2 –