I am using LayerMapping to add a shapefile into the database. Here is the code I am using. The shapefile is ~100MB so there are a bunch of polygons to add.
mapping = {'name': 'OBJECTID', 'poly': 'POLYGON'}
lm = LayerMapping(TestGeo, 'toronto geo/PROPERTY_BOUNDARIES_WGS84.shp', mapping)
lm.save(verbose=True)
After running the above code, I'd see about 10 seconds of success messages, showing something like Saved: 'name': 12345
. Then 10 seconds later, the messages turn into:
Failure to save: {'name': 12345, 'poly': (....)}: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
It still keeps running after displaying the error message (I'm guessing it moved onto the next polygon object). After it goes through each polygon, despite the fact that the first couple hundred or so polygons showed a success message, none of the polygons from the shapefile were saved.
I came across a similar error but the content doesn't seem to be related.
Any idea why this is happening?