Migration wrapper that checks foreign keys.

    Note that this may raise different exceptions depending on the
    underlying database API.

def CheckForeignKeysWrapper(conn):
    """Migration wrapper that checks foreign keys.

    Note that this may raise different exceptions depending on the
    underlying database API.
    """
    yield
    cur = conn.cursor()
    cur.execute('PRAGMA foreign_key_check')
    errors = cur.fetchall()
    if errors:
        raise ForeignKeyError(errors)