def syncdb(verbosity=1, interactive=True):
 from django.db import connection, transaction, models, get_creation_module
 from django.conf import settings
 disable_termcolors()
 _check_for_validation_errors()
 for app_name in settings.INSTALLED_APPS:
  try:
   __import__((app_name + '.management'), {}, {}, [''])
  except ImportError:
   pass
 data_types = get_creation_module().DATA_TYPES
 cursor = connection.cursor()
 table_list = _get_table_list()
 seen_models = _get_installed_models(table_list)
 created_models = set()
 pending_references = {}
 for app in models.get_apps():
  app_name = app.__name__.split('.')[(-2)]
  model_list = models.get_models(app)
  for model in model_list:
   if (verbosity >= 2):
    print ('Processing %s.%s model' % (app_name, model._meta.object_name))
   if (model._meta.db_table in table_list):
    continue
   (sql, references) = _get_sql_model_create(model, seen_models)
   seen_models.add(model)
   created_models.add(model)
   for (refto, refs) in references.items():
    pending_references.setdefault(refto, []).extend(refs)
   sql.extend(_get_sql_for_pending_references(model, pending_references))
   if (verbosity >= 1):
    print ('Creating table %s' % model._meta.db_table)
   for statement in sql:
    cursor.execute(statement)
   table_list.append(model._meta.db_table)
 for app in models.get_apps():
  app_name = app.__name__.split('.')[(-2)]
  model_list = models.get_models(app)
  for model in model_list:
   if (model in created_models):
    sql = _get_many_to_many_sql_for_model(model)
    if sql:
     if (verbosity >= 2):
      print ('Creating many-to-many tables for %s.%s model' % (app_name, model._meta.object_name))
     for statement in sql:
      cursor.execute(statement)
 transaction.commit_unless_managed()
 _emit_post_sync_signal(created_models, verbosity, interactive)
 for app in models.get_apps():
  for model in models.get_models(app):
   if (model in created_models):
    custom_sql = get_custom_sql_for_model(model)
    if custom_sql:
     if (verbosity >= 1):
      print ('Installing custom SQL for %s.%s model' % (app_name, model._meta.object_name))
     try:
      for sql in custom_sql:
       cursor.execute(sql)
     except Exception as e:
      sys.stderr.write(('Failed to install custom SQL for %s.%s model: %s' % (app_name, model._meta.object_name, e)))
      transaction.rollback_unless_managed()
     else:
      transaction.commit_unless_managed()
 for app in models.get_apps():
  app_name = app.__name__.split('.')[(-2)]
  for model in models.get_models(app):
   if (model in created_models):
    index_sql = get_sql_indexes_for_model(model)
    if index_sql:
     if (verbosity >= 1):
      print ('Installing index for %s.%s model' % (app_name, model._meta.object_name))
     try:
      for sql in index_sql:
       cursor.execute(sql)
     except Exception as e:
      sys.stderr.write(('Failed to install index for %s.%s model: %s' % (app_name, model._meta.object_name, e)))
      transaction.rollback_unless_managed()
     else:
      transaction.commit_unless_managed()
 load_data(['initial_data'], verbosity=verbosity)

def syncdb ( verbosity = 1 , interactive = True ) : from django . db import connection , transaction , models , get_creation_module from django . conf import settings disable_termcolors ( ) _check_for_validation_errors ( ) for app_name in settings . INSTALLED_APPS : try : __import__ ( ( app_name + '.management' ) , { } , { } , [ '' ] ) except ImportError : pass data_types = get_creation_module ( ) . DATA_TYPES cursor = connection . cursor ( ) table_list = _get_table_list ( ) seen_models = _get_installed_models ( table_list ) created_models = set ( ) pending_references = { } for app in models . get_apps ( ) : app_name = app . __name__ . split ( '.' ) [ ( - 2 ) ] model_list = models . get_models ( app ) for model in model_list : if ( verbosity >= 2 ) : print ( 'Processing %s.%s model' % ( app_name , model . _meta . object_name ) ) if ( model . _meta . db_table in table_list ) : continue ( sql , references ) = _get_sql_model_create ( model , seen_models ) seen_models . add ( model ) created_models . add ( model ) for ( refto , refs ) in references . items ( ) : pending_references . setdefault ( refto , [ ] ) . extend ( refs ) sql . extend ( _get_sql_for_pending_references ( model , pending_references ) ) if ( verbosity >= 1 ) : print ( 'Creating table %s' % model . _meta . db_table ) for statement in sql : cursor . execute ( statement ) table_list . append ( model . _meta . db_table ) for app in models . get_apps ( ) : app_name = app . __name__ . split ( '.' ) [ ( - 2 ) ] model_list = models . get_models ( app ) for model in model_list : if ( model in created_models ) : sql = _get_many_to_many_sql_for_model ( model ) if sql : if ( verbosity >= 2 ) : print ( 'Creating many-to-many tables for %s.%s model' % ( app_name , model . _meta . object_name ) ) for statement in sql : cursor . execute ( statement ) transaction . commit_unless_managed ( ) _emit_post_sync_signal ( created_models , verbosity , interactive ) for app in models . get_apps ( ) : for model in models . get_models ( app ) : if ( model in created_models ) : custom_sql = get_custom_sql_for_model ( model ) if custom_sql : if ( verbosity >= 1 ) : print ( 'Installing custom SQL for %s.%s model' % ( app_name , model . _meta . object_name ) ) try : for sql in custom_sql : cursor . execute ( sql ) except Exception as e : sys . stderr . write ( ( 'Failed to install custom SQL for %s.%s model: %s' % ( app_name , model . _meta . object_name , e ) ) ) transaction . rollback_unless_managed ( ) else : transaction . commit_unless_managed ( ) for app in models . get_apps ( ) : app_name = app . __name__ . split ( '.' ) [ ( - 2 ) ] for model in models . get_models ( app ) : if ( model in created_models ) : index_sql = get_sql_indexes_for_model ( model ) if index_sql : if ( verbosity >= 1 ) : print ( 'Installing index for %s.%s model' % ( app_name , model . _meta . object_name ) ) try : for sql in index_sql : cursor . execute ( sql ) except Exception as e : sys . stderr . write ( ( 'Failed to install index for %s.%s model: %s' % ( app_name , model . _meta . object_name , e ) ) ) transaction . rollback_unless_managed ( ) else : transaction . commit_unless_managed ( ) load_data ( [ 'initial_data' ] , verbosity = verbosity )
sync loacl db with remote db .