How to set a default value for attributes in shapefiles in QGIS?

QGIS 3

Select the layer in the layer panel and left-click. Select properties. Select the "Attributes Form" as shown below. Select the fields from the "Available Widgets" list as show. Provide an expression for the default value in the "Defaults" dialog. If the "Apply default value on update" is checked, the value will be adjusted every time the feature's geometry or another attribute is changed. This makes things like a "last_modified" timestamp or an updated "area" possible.

Set Field Default Value QGIS 3.0.3


QGIS 2.18

Starting from QGIS 2.18 this is possible without any extra tools.

Just go to the field properties click on the button in the field you would like to assign a default value and enter an expression. It can also take the geometry as input.

enter image description here

Sidenote: I know that the original question targets QGIS 2.14, but I think this is still of interest to future readers of this question.


There is the AutoFields plugin which allows you to create (or modify) attribute fields and update them automatically with a custom expression.

It has also been tested with various formats and autofields are not considered to be virtual fields (quoted from the plugin's homepage):

Do AutoFields work with ‘X’ vector format?

We’ve already tested AutoFields on PostgreSQL/PostGIS, SpatiaLite, Shapefiles, WFS-T (Transactional Web Feature Service) and Memory layers. Please let me know if you use AutoFields on other vector formats.

Are AutoFields like Virtual Fields?

Nope. Unlike Virtual Fields, AutoFields:

  • Store calculated values in the data;
  • Are independent of QGIS projects, i.e., you can switch between QGIS projects and AutoFields will still work;
  • Only work on editable vector layers.

Since I would like to use these attributes values mentioned above to control some aspects of symbology (symbol size, opacity), some further research revealed that with data defined properties there is another great (and flexible) way to achieve this. A (generic) expression

if("attribute_name" is null, @default_value, "attribute_name")

where @default_value is defined as a projects variable, returns a default that can be defined by the user when no value is set for the attribute attribute_name and it's value else.

Define variables in project properties:

enter image description here

Set up an expression with data defined properties (red color with user defined opacity in this case):

enter image description here