The tables in question are:
enquiry
- id
- accepted_quote_id
supplier_enquiry
- id
- enquiry_id
quote
- id
- enquiry_id
- supplier_enquiry_id
The constraints are as follows:
CONSTRAINT
supplier_enquiry_ibfk_1
FOREIGN KEY (enquiry_id
) REFERENCESenquiry
(id
) ON DELETE CASCADECONSTRAINT
quote_ibfk_1
FOREIGN KEY (supplier_enquiry_id
) REFERENCESsupplier_enquiry
(id
) ON DELETE CASCADECONSTRAINT
enquiry_ibfk_9
FOREIGN KEY (accepted_q开发者_开发技巧uote_id
) REFERENCESquote
(id
)
So the way I expect this to work is:
- If you delete an 'enquiry' it deletes the child 'supplier_enquiry' records
- If you delete a 'supplier_enquiry' it deletes the child 'quote' records
- You cannnot delete a 'quote' if an 'enquiry' references that quote's ID
The problem I'm having is when deleting an 'enquiry' record. Because it needs to delete the child records first, i.e. 'supplier_enquiry' and 'quote', if 'accepted_quote_id' references a 'quote' then the 'enquiry' can't be deleted.
Any idea how I can overcome this issue?
You get rid of the circular reference by making the two other tables dependant on enquiry.
So:
quote.enquiry_id references enquiry.id
And:
supplier_enquiry.enquiry_id references enquiry.id
EDIT: That might be unclear. I'm suggesting making a new constraint on the quote table that references enquiry_id to enquiry.id, then removing enquiry_ibfk_9
Update the reference to NULL before deleting.
精彩评论