'Creates the SQL snippet for a column. Used by add_column and add_table.'

def column_sql(self, table_name, field_name, field, tablespace='', with_name=True, field_prepared=False):

    if (not field_prepared):
        field.set_attributes_from_name(field_name)
    if hasattr(field, 'south_init'):
        field.south_init()
    field = self._field_sanity(field)
    try:
        sql = field.db_type(connection=self._get_connection())
    except TypeError:
        sql = field.db_type()
    if sql:
        if with_name:
            field_output = [self.quote_name(field.column), sql]
        else:
            field_output = [sql]
        if field.primary_key:
            field_output.append('NOT    NULL    PRIMARY    KEY')
        elif field.unique:
            field_output.append('UNIQUE')
        sql = '    '.join(field_output)
        sqlparams = ()
        if (not getattr(field, '_suppress_default', False)):
            if field.has_default():
                default = field.get_default()
                if (default is not None):
                    if callable(default):
                        default = default()
                    if isinstance(default, string_types):
                        default = ("'%s'" % default.replace("'", "''"))
                    elif isinstance(default, (datetime.date, datetime.time, datetime.datetime)):
                        default = ("'%s'" % default)
                    elif isinstance(default, bool):
                        default = int(default)
                    if isinstance(default, string_types):
                        default = default.replace('%', '%%')
                    sql += '    DEFAULT    %s'
                    sqlparams = default
            elif (((not field.null) and field.blank) or (field.get_default() == '')):
                if (field.empty_strings_allowed and self._get_connection().features.interprets_empty_strings_as_nulls):
                    sql += "    DEFAULT    ''"
        if ((not field.primary_key) and (not field.null)):
            sql += '    NOT    NULL'
        if (field.rel and self.supports_foreign_keys):
            self.add_deferred_sql(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))
    if hasattr(field, 'post_create_sql'):
        for stmt in field.post_create_sql(no_style(), table_name):
            self.add_deferred_sql(stmt)
    if (not field.rel):
        if hasattr(self._get_connection().creation, 'sql_indexes_for_field'):
            model = self.mock_model('FakeModelForGISCreation', table_name)
            for stmt in self._get_connection().creation.sql_indexes_for_field(model, field, no_style()):
                self.add_deferred_sql(stmt)
    if sql:
        return (sql % sqlparams)
    else:
        return None
