@filters("sqlite", sqla_exc.IntegrityError,
         r"(?i).*foreign key constraint failed")
@filters("postgresql", sqla_exc.IntegrityError,
         r".*on table \"(?P<table>[^\"]+)\" violates "
         "foreign key constraint \"(?P<constraint>[^\"]+)\".*\n"
         "DETAIL:  Key \((?P<key>.+)\)=\(.+\) "
         "is (not present in|still referenced from) table "
         "\"(?P<key_table>[^\"]+)\".")
@filters("mysql", sqla_exc.IntegrityError,
         r".* u?'Cannot (add|delete) or update a (child|parent) row: "
         'a foreign key constraint fails \([`"].+[`"]\.[`"](?P<table>.+)[`"], '
         'CONSTRAINT [`"](?P<constraint>.+)[`"] FOREIGN KEY '
         '\([`"](?P<key>.+)[`"]\) REFERENCES [`"](?P<key_table>.+)[`"] ')
def _foreign_key_error(integrity_error, match, engine_name, is_disconnect):

    try:
        table = match.group("table")
    except IndexError:
        table = None
    try:
        constraint = match.group("constraint")
    except IndexError:
        constraint = None
    try:
        key = match.group("key")
    except IndexError:
        key = None
    try:
        key_table = match.group("key_table")
    except IndexError:
        key_table = None

    raise exception.DBReferenceError(table, constraint, key, key_table,
                                     integrity_error)
Filter for foreign key errors.
dataset/ETHPy150Open openstack/oslo.db/oslo_db/sqlalchemy/exc_filters.py/_foreign_key_error