(db_alias)
PostgreSQL does not support disabling constraint checks like MySQL.
    But you can defer them until transaction commit. Django's
    ``DatabaseWrapper`` for PostgreSQL doesn't have a method for this,
    so we need to execute raw SQL.
PostgreSQL does not support disabling constraint checks like MySQL.
    But you can defer them until transaction commit. Django's
    ``DatabaseWrapper`` for PostgreSQL doesn't have a method for this,
    so we need to execute raw SQL.
PostgreSQL does not support disabling constraint checks like MySQL . But you can defer them until transaction commit . Django s DatabaseWrapper for PostgreSQL doesn t have a method for this so we need to execute raw SQL .
def constraint_checks_deferred(db_alias):
    """
    PostgreSQL does not support disabling constraint checks like MySQL.
    But you can defer them until transaction commit. Django's
    ``DatabaseWrapper`` for PostgreSQL doesn't have a method for this,
    so we need to execute raw SQL.
    """
    connection = connections[db_alias]
    with connection.cursor() as cursor:
        cursor.execute('SET CONSTRAINTS ALL DEFERRED')
        try:
            yield
        finally:
            if not cursor.db.needs_rollback:
                cursor.execute('SET CONSTRAINTS ALL IMMEDIATE')
def constraint_checks_deferred ( db_alias ) : connection = connections [ db_alias ] with connection . cursor ( ) as cursor : cursor . execute ( 'SET CONSTRAINTS ALL DEFERRED' ) try : yield finally : if not cursor . db . needs_rollback : cursor . execute ( 'SET CONSTRAINTS ALL IMMEDIATE' )