cidade have many cliente and clientw have one cidade
when i try delete cidade:
Fatal error: Uncaught exception ‘epExceptionDbAdodb’ with message 'Cannot execute query: mysql error: [1452: Cannot add or update a child row: a foreign key constraint fails (alianza/cliente, CONSTRAINT cliente_ibfk_1 FOREIGN KEY (cidade_id) REFERENCES cidade (id) ON DELETE CASCADE ON UPDATE CASCADE)] in EXECUTE(“Update cliente SET cidade_id = Null WHERE id = 3 OR id = 4 OR id = 5 OR id = 6 OR id = 7 OR id = 8 OR id = 9 OR id = 10 OR id = 11 OR id = 12 OR id = 13 OR id = 14 OR id = 15 OR id = 16 OR id = 17 OR id = 18 OR id = 19 OR id = 20 OR id = 21 OR id = 22 OR id = 23 OR id = 24 OR id = 25 OR id = 26 OR id = 27 OR id = 28 OR id = 29 OR id = 30 OR id = 31 OR id = 32 OR id = 33 OR id = 34 OR id = 35 OR id = 36 OR id = 37 OR id = 38 OR id = 39 OR id = 40 OR id = 41 OR id = 42 OR id = 43 OR id = 44 OR id = 45 OR id = 46 OR id = 47 OR id = 48 OR id = 49 OR id = 50 OR id = 51 OR id = 52”) ’ in D:\workPHP\alianza\lib\phporm\src\db\epDbAdodb.php:188 Stack trace: #0 D:\workPHP\alianza\lib\phporm\src\db\epDb.php(352): in D:\workPHP\alianza\lib\phporm\src\db\epDbAdodb.php on line 188
According to your description, your problem most likely caused by the FK for both cidade and cliente are not nullable. You should have either one side set to nullable in order to make it work. Besides, you should loop through and delete the cliente before delete cidade (See below). If you have any further inquiries, please do not hesitate to contact me again.
foreach($cidade->getClientes() as $lClientes) {
$lClientes->delete();
}
$cidade->delete();
Please make sure your association is in composition type in order to have the cascade effect. If you require any further information, please do not hesitate to contact me.