Bug fixing foreign key on delete