def _get_sql_for_pending_references(model, pending_references):
 from django.db import backend, get_creation_module
 data_types = get_creation_module().DATA_TYPES
 final_output = []
 if backend.supports_constraints:
  opts = model._meta
  if (model in pending_references):
   for (rel_class, f) in pending_references[model]:
    rel_opts = rel_class._meta
    r_table = rel_opts.db_table
    r_col = f.column
    table = opts.db_table
    col = opts.get_field(f.rel.field_name).column
    r_name = ('%s_refs_%s_%x' % (r_col, col, abs(hash((r_table, table)))))
    final_output.append((style.SQL_KEYWORD('ALTER TABLE') + (' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % (backend.quote_name(r_table), r_name, backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col), backend.get_deferrable_sql()))))
   del pending_references[model]
 return final_output

def _get_sql_for_pending_references ( model , pending_references ) : from django . db import backend , get_creation_module data_types = get_creation_module ( ) . DATA_TYPES final_output = [ ] if backend . supports_constraints : opts = model . _meta if ( model in pending_references ) : for ( rel_class , f ) in pending_references [ model ] : rel_opts = rel_class . _meta r_table = rel_opts . db_table r_col = f . column table = opts . db_table col = opts . get_field ( f . rel . field_name ) . column r_name = ( '%s_refs_%s_%x' % ( r_col , col , abs ( hash ( ( r_table , table ) ) ) ) ) final_output . append ( ( style . SQL_KEYWORD ( 'ALTER TABLE' ) + ( ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % ( backend . quote_name ( r_table ) , r_name , backend . quote_name ( r_col ) , backend . quote_name ( table ) , backend . quote_name ( col ) , backend . get_deferrable_sql ( ) ) ) ) ) del pending_references [ model ] return final_output
get any alter table statements to add constraints after the fact .