While running the following
canvas = qgis.utils.iface.mapCanvas()
layer = canvas.currentLayer()
print(layer.name())
options = QgsVectorFileWriter.SaveVectorOptions()
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer
#options.layerName = "_".join(layer.name().split(' '))
writer = QgsVectorFileWriter.writeAsVectorFormat(layer, "C:/Users/ilyasse2.0/Documents/SQRLAND/hh.gpkg", options)
print(writer)
I get this error :
(2, 'Opening of data source in update mode failed (OGR error: )')
The layer is created by with
layer = QgsVectorLayer("Point", 'layerName', "memory")
I tried to use this solution: Adding layer to GeoPackage using PyQGIS but it is not working for me.