It fails with this error
IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`tracker_main`.`tracker_notification`, CONSTRAINT `tracker_notifica_ticket_id_59e3495a9a2568da_fk_tracker_ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `tracker_ticket` (`id`))')
This is from ticket with notifications. It wasn't possible to delete the ticket even after manually purging the notifications (by running DELETE FROM tracker_notification WHERE ticket_id=1596; in SQL console) and restarting Uwsgi (by running touch deploy/reload), with the same error.
I tried to reproduce the same situation on tracker2 (test setup), by doing the following:
- Create test user, with email address.
- Add that test user as an admin to a topic
- Under other account I created a ticket in that topic
- I checked in DB, if notifications were scheduled, they were
- I tried to delete the ticket via admin interface
- I was warned that it will delete Notification object as well.
- The ticket deleted successfully
The test server was running f7394b9, production server was running e1b0bdb3f2cb02a33c0d37d830a6132dc5e88591, but it was working like above even after upgrading.
However, when I tried to add some acks between step 3 and 4 to have other notification objects created, I got the above error while deleting.
I also tried to create a ticket in topic with more than one administrator (so more than one notification of same type is issued). There were no problems with it.
I tried to delete the test ticket again after notifications were distributed (by regular daily digest, I did not force it), it failed with the following error.
IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`tracker_test`.`tracker_notification`, CONSTRAINT `tracker_notifica_ticket_id_59e3495a9a2568da_fk_tracker_ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `tracker_ticket` (`id`))')
Conclusion: it is not possible to delete a tiket that caused notification about at least two events using Django internal mechanism.
When I tried to do DELETE FROM tracker_ticket WHERE id=1596, it succeeded on my first try.