#NEWLINE# def database_forwards( self , app_label , schema_editor , from_state , to_state , engine = None ) : #NEWLINE# #INDENT# if ( engine is None ) : #NEWLINE# #INDENT# engine = self . engine #NEWLINE# #UNINDENT# if hasattr ( to_state , 'render' ) : #NEWLINE# #INDENT# apps = to_state . render ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# apps = to_state . apps #NEWLINE# #UNINDENT# new_model = apps . get_model ( app_label , self . name ) #NEWLINE# if hasattr ( self , 'allowed_to_migrate' ) : #NEWLINE# #INDENT# allowed = self . allowed_to_migrate #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# allowed = self . allow_migrate_model #NEWLINE# #UNINDENT# qn = schema_editor . connection . ops . quote_name #NEWLINE# if allowed ( schema_editor . connection . alias , new_model ) : #NEWLINE# #INDENT# with schema_editor . connection . cursor ( ) as cursor : #NEWLINE# #INDENT# cursor . execute ( 'SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES\n                       WHERE TABLE_SCHEMA=DATABASE() AND\n                             TABLE_NAME = %s AND\n                             ENGINE = %s' , ( new_model . _meta . db_table , engine ) ) #NEWLINE# uses_engine_already = ( cursor . fetchone ( ) [ 0 ] > 0 ) #NEWLINE# #UNINDENT# if uses_engine_already : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# schema_editor . execute ( 'ALTER TABLE {table} ENGINE={engine}' . format ( table = qn ( new_model . _meta . db_table ) , engine = engine ) )