# File app/controllers/sys_conf_adm_controller.rb, line 64
  def create_table_field
    redirect_to :action => :list_table_fields, :table => @table
    return true unless request.post?

    # Several things can go wrong when creating a column - In order
    # not to leave the DB in a state we don't want to, and to avoid
    # having the code too messed up with validations and if/elses,
    # just rescue it in case of failure.
    begin
      field = params[:fldname].downcase
      type = params[:fldtype].to_sym
      default = params[:flddefault]
      default = nil if default.blank?

      field =~ /^\w[\d\w\_]+$/ or raise NameError, _('Invalid column name') 
      raise NameError, _('A field by that name is already defined') if
        @model.column_names.include?(field) 
      raise TypeError, _('Invalid data type specified') unless
        @types.include?(type)

      if type == :catalog
        # A catalog is not a native type - fake it!
        catalog = field.pluralize
        ActiveRecord::Base.transaction do
          @model.connection.create_catalogs(catalog)
          @model.connection.add_reference(@table, catalog, :default => default)
        end
      else
        @model.connection.add_column(@table, field, type, :default => default)
      end

      flash[:notice] << _("Successfully created %s field in %s") % 
        [field, @table]

    rescue TypeError, NameError, ActiveRecord::StatementInvalid => err
      flash[:error] << _('Unable to create requested column: %s') % err
    end
  end