mysql - How to delete two rows together with foreign key relationship -
i have 2 tables , these 2 have relationship like
class lesson { /** * @var integer * * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ private $id; class ticketuse { /** * * @orm\manytoone(targetentity="acme\userbundle\entity\lesson") * @orm\joincolumn(name="lessonid", referencedcolumnname="id") */ private $lessonid;
these 2 tables relation ships are.
if row in lesson exist,a row in ticketuse exists or doesn't exist.
if row in ticketuse exists has combination row in lesson.
when try delete lesson row 'delete lesson id = 1'
it shows error.
sqlstate[23000]: integrity constraint violation: 1451 cannot delete or update parent row: foreign key constraint fails
i want delete ticketuse automatically,when delete lesson.
is there way delete both together?
i have 2 write delete sentences each?
for foreign key relationship, add on update cascade.
able delete according needs.
when delete parent change automatically reflected child.
Comments
Post a Comment