Safe checking for foreign key existence for db teardown