Bug report #17899

Shape to Geopackage: Creation of field fid failed (OGR error: Wrong field type for fid)

Added by Richard Duivenvoorde almost 7 years ago. Updated over 5 years ago.

Status:Feedback
Priority:Normal
Assignee:-
Category:Vectors
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:25795

Description

Loading attached shapefile (in current master, epsg:28992) and then trying to save it as a Geoapackage (also epsg:28992) fails giving the following error:

Export to vector file failed.
Error: Creation of field fid failed (OGR error: Wrong field type for fid)

Versions error:

QGIS version
2.99.0-Master
QGIS code revision
f274456fce
Compiled against Qt
5.9.2
Running against Qt
5.9.2
Compiled against GDAL/OGR
2.2.3
Running against GDAL/OGR
2.2.3
Compiled against GEOS
3.6.2-CAPI-1.10.2
Running against GEOS
3.6.2-CAPI-1.10.2 4d2925d6
PostgreSQL Client Version
10.1
SpatiaLite Version
4.3.0a
QWT Version
6.1.2
PROJ.4 Version
493
QScintilla2 Version
2.9.3
This copy of QGIS writes debugging output.

prov.zip - epsg:28992 data (65.4 KB) Richard Duivenvoorde, 2018-01-20 03:28 PM

Selection_293.png - empty primary key column (57.6 KB) Richard Duivenvoorde, 2018-02-02 03:58 PM

History

#1 Updated by Jérôme Guélat almost 7 years ago

This also happens in QGIS 2.18. I think this is related to the fact that the fid column type is double (real) instead of integer.

In my case this was caused by another bug. When you export a GeoPackage to Shapefile, QGIS converts the fid column to double (real) instead of keeping the original type (qlonglong, Integer64). And then the bug you reported occurs when you try to export this Shapefile back to GeoPackage.

#2 Updated by Richard Duivenvoorde almost 7 years ago

Ah, I think you are right.

Just saving the layer as is fails.

BUT if you open the 'Layer Options' item in the 'Save Vector Layer as...' dialog, en REMOVE the 'fid' in the 'FID' field (so it is empty), THEN all is fine...

Funny though, looking that the GeoPackage created:
- the primary column used now is indeed INTEGER Not NULL, BUT it does not have a column name... (see screenshot)

Looking into it with sqlitebrowser and looking that the create string, it says:

CREATE TABLE "zz" ( "" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "geom" MULTIPOLYGON, "fid" REAL, "PROVC" REAL, "PROVC_NM" TEXT, "INW_T" INTEGER)

So I think there are two things to fix:

- the 'guesssing' of the 'Layer Options' should be smarter? As in: IF there is a fid, only use it as FID if the type is integer?
- IF the fid is removed in the QGIS dialog give it a random name (even IF there is already a fid column... ?

#3 Updated by Mike Bannister about 6 years ago

I ran into a similar problem w/ FIDs while exporting to geopackage. A line shapefile w/ multiple part features was exploded, resulting in multiple features with the same fid. Attempting to export to geopackage resulted in the error below. Deleting 'fid' from the 'FID' field as described above allowed a successful export.

Export to vector file failed.
Error: Feature write errors:
Feature creation error (OGR error: failed to execute insert : UNIQUE constraint failed: asdf.fid)
Feature creation error (OGR error: failed to execute insert : UNIQUE constraint failed: asdf.fid)
...
Feature creation error (OGR error: failed to execute insert : UNIQUE constraint failed: asdf.fid)
Feature creation error (OGR error: failed to execute insert : UNIQUE constraint failed: asdf.fid)
Only 38 of 146 features written.

#4 Updated by Giovanni Manghi over 5 years ago

  • Status changed from Open to Feedback

Please check if this issue is still valid on QGIS 3.4.5 or 3.6.

Also available in: Atom PDF