#NEWLINE# @ generic . invalidate_table_constraints #NEWLINE# def alter_column( self , table_name , name , field , explicit_name = True , ignore_constraints = False ) : #NEWLINE# #INDENT# '\n        Alters the given column name so it will match the given field.\n        Note that conversion between the two by the database must be possible.\n        Will not automatically add _id by default; to have this behavour, pass\n        explicit_name=False.\n\n        @param table_name: The name of the table to add the column to\n        @param name: The name of the column to alter\n        @param field: The new field definition to use\n        ' #NEWLINE# if self . dry_run : #NEWLINE# #INDENT# if self . debug : #NEWLINE# #INDENT# print ( '   - no dry run output for alter_column() due to dynamic DDL, sorry' ) #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# if hasattr ( field , 'south_init' ) : #NEWLINE# #INDENT# field . south_init ( ) #NEWLINE# #UNINDENT# field . set_attributes_from_name ( name ) #NEWLINE# if ( not explicit_name ) : #NEWLINE# #INDENT# name = field . column #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# field . column = name #NEWLINE# #UNINDENT# if ( not ignore_constraints ) : #NEWLINE# #INDENT# self . _drop_constraints ( table_name , values , field ) #NEWLINE# #UNINDENT# params = { #NEWLINE# #INDENT# 'column' : self . quote_name ( name ) , #NEWLINE# 'type' : self . _db_type_for_alter_column ( field ) , #NEWLINE# 'table_name' : table_name , #NEWLINE# #UNINDENT# } #NEWLINE# sqls = [ ] #NEWLINE# sqls_extra = [ ] #NEWLINE# if ( params [ 'type' ] is not None ) : #NEWLINE# #INDENT# sqls . append ( ( ( self . alter_string_set_type % params ) , [ ] ) ) #NEWLINE# #UNINDENT# self . _alter_add_column_mods ( field , name , params , sqls ) #NEWLINE# sqls_extra . append ( self . _alter_column_set_null ( table_name , name , field . null ) ) #NEWLINE# self . _alter_set_defaults ( field , name , params , sqls ) #NEWLINE# if self . allows_combined_alters : #NEWLINE# #INDENT# ( sqls , values ) = list ( zip ( * sqls ) ) #NEWLINE# self . execute ( ( 'ALTER TABLE %s %s;' % ( self . quote_name ( table_name ) , ', ' . join ( sqls ) ) ) , generic . flatten ( values ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for ( sql , values ) in sqls : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . execute ( ( 'ALTER TABLE %s %s;' % ( self . quote_name ( table_name ) , sql ) ) , values ) #NEWLINE# #UNINDENT# except DatabaseError as e : #NEWLINE# #INDENT# print ( e ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for sql in sqls_extra : #NEWLINE# #INDENT# self . execute ( sql ) #NEWLINE# #UNINDENT# if ( not ignore_constraints ) : #NEWLINE# #INDENT# if ( field . rel and self . supports_foreign_keys ) : #NEWLINE# #INDENT# self . execute ( self . foreign_key_sql ( table_name , field . column , field . rel . to . _meta . db_table , field . rel . to . _meta . get_field ( field . rel . field_name ) . column ) )