# File app/controllers/sys_conf_adm_controller.rb, line 130
  def edit_table_field
    fld = params[:field].to_sym
    begin
      @field = @model.extra_listable_attributes.select {|a|
        a.name.to_sym == fld }[0] or raise NameError
    rescue NameError
      redirect_to :action => 'list_table_fields', :table => @table
      flash[:error] << _('Invalid field specified')
      return false
    end
    return true unless request.post?

    name = @field.name
    default = params[:default]
    default = nil if default.blank?
    # Null handling can be a bit tricky, as setting it to false can
    # require updating all the null records (setting them to the
    # default)
    null = (params[:null_ok] == true)

    redirect_to :action => :list_table_fields, :table => @table
    begin
      @model.connection.change_column_default(@table, name, default)
    rescue ActiveRecord::StatementInvalid => err
      flash[:error] << _('Error setting the requested default value: %s') %
        err
      return false
    end

    if null
      # Granting permission to set it to null? Ok, just proceed...
      @model.connection.change_column_null(@table, name, true)
    elsif !@field.null 
      # Is the field already rejecting null values? Good, then this is
      # a no-op!
    else
      if ! @field.default.blank?
        # Good, we have a default value - Set it wherever
        # needed. Anyway, this is prone to fail, so...
        begin
          @model.connection.select_all("UPDATE %s set %s = %s WHERE %s IS NULL"%
                                       [@table, name, @field.default, 
                                        name])
          # And now, the magic!
          @model.connection.change_column_null(@table, name, false)
        rescue ActiveRecord::StatementInvalid => err
          flash[:error] << _("Error setting the field as not null: %s") % err
          return false
        end
      else
        # Sorry, not much we can do...
        flash[:error] << _('Cannot set field %s to reject null values: No ' +
                           'default value ') % name
        return false
      end
    end

    flash[:notice] << _("The field's values were correctly updated")
  end