Skip to main content
1 of 3
MrXsquared
  • 35.6k
  • 22
  • 71
  • 121

For PyQGIS 3 this might be the easiest way:

# Get a layer object and enter edit mode:
my_vectorlayer = iface.activeLayer()
with edit(my_vectorlayer):
    # Get the field index by its name:
    my_field = my_vectorlayer.fields().indexFromName('name of field you want to delete')
    # Delete the field by its index, note that it has to be in a list:
    my_vectorlayer.dataProvider().deleteAttributes([my_field])
# Update the fields, so the changes are recognized:
my_vectorlayer.updateFields()
MrXsquared
  • 35.6k
  • 22
  • 71
  • 121