MDL-42865 Make XMLDB foreign key check more robust.

Otherwise, installing one bad add-on can completely break this report.