Using python, sqlalchemy and the psycopg2 driver, I am trying to go from a shapefile to a geodataframe, to a postgres database with postgis installed foloowing this question
I converted the geometry to a WKB hex string, and using df.to_sql()
imported the standard data frame successfully.
Upon running the alter table
query I'm getting the error:
sqlalchemy.exc.DataError: (psycopg2.errors.InvalidParameterValue) Geometry type (MultiPolygon) does not match column type (Polygon)
This is because the shapefile will indicate a geometry type that can be either Polygon or Multipolygon for a given row of the resulting geodataframe.
This info is included when converting to Well-Known-Binary hex string and creates a type problem when converting the text to geometry.
The explode function from mhweber's gist will fix that by breaking multipolygons into their componenet parts.
I've added a side effect to print the number of multipolygons found.
Odds are you should investigate these to be sure that the explode function isn't breaking relationships that you need.