title: PostGIS: Converting Text WKT/WKB/WKB Hex to Polygon
body: <p>I am importing Polygon shapes into a PostGIS database, using Python (GeoPandas, SQLAlchemy, GeoAlchemy2). I followed the instructions mentioned <a href="https://stackoverflow.com/questions/38361336/write-geodataframe-into-sql-database/43375829">here</a>.</p>
  
  <p>I have a database with a table named <code>maps_region</code> with a column/field called <code>geom</code>.</p>
  
  <p>I am able to get the Polygon field (named <code>geom</code>) to import into the PostGIS database table in text format (WKT, WKB, and WKB Hex), but, I am unable to successfully convert this text column into a proper Polygon format in the database.</p>
  
  <p>I tried importing with the <code>geom</code> field in several different formats-- in Well-Known Text (WKT) format, WKB format, and WKB Hex format-- but could not convert to Polygon from any of the three formats.</p>
  
  <p>For instance, I imported the shapes into the <code>geom</code> field as WKT format, and then converted to WKB Hex format, using the following command, which worked fine:</p>
  
  <pre><code>database=&gt; UPDATE maps_region SET geom = ST_GeomFromText(geom, 4326);
  UPDATE 28
  </code></pre>
  
  <p>However, when I then try to convert the <code>geom</code> field from a <code>text</code> format into a <code>Polygon</code> type, I get the following errors: </p>
  
  <pre><code>database=&gt; ALTER TABLE maps_region ALTER COLUMN geom TYPE Geometry(POLYGON, 4326);
  ERROR:  Geometry type (MultiPolygon) does not match column type (Polygon)
  database=&gt; ALTER TABLE maps_region ALTER COLUMN geom TYPE Geometry(MULTIPOLYGON, 4326);
  ERROR:  Geometry type (Polygon) does not match column type (MultiPolygon)
  </code></pre>
  
  <p>I tried both ways: converting to Polygon, and converting to MultiPolygon-- and neither worked. Instead, the error messages were just reversed!</p>
  
  <p>Any help would be greatly, greatly appreciated.</p>
  
  <p>Thanks in advance!</p>