Using Symfony 2.8.24, Doctrine 2 and Jsor's doctrine-postgis library, the latter to make Doctrine get along with spatial types like geometry, geography, etc.

So, I have a table with a column of type geometry(MultiPolygon, 3795), at least it is presented as so in pgAdmin III (I'm using OpenGeo's pgAdmin which includes the postgis extension, along with plpgsql)

I have the tables with the spatial info, so I created my entities from those tables, via doctrine:mapping:import and doctrine:mapping:convert commands, which indeed created the corresponding php classes without an issue.

THE PROBLEM came when I made some changes to other entities in my project, entities which did not even have spatial type attributes, after that I tried to "doctrine:schema:update" "--force" to sync the database with my new changes and I get the error from the title

The geometry_type of a spatial column cannot be changed (Requested changing type from "MULTIPOLYGON" to "GEOMETRY" for column "geom" in table "X")

Fragment of the entity class as generated by the commands:

 * TableName
 * @ORM\Table(name="TableName", indexes={@ORM\Index(name="sidx_table_name_geom", columns={"geom"})})
 * @ORM\Entity
class TableName {

     * @var integer
     * @ORM\Column(name="gid", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="SEQUENCE")
     * @ORM\SequenceGenerator(sequenceName="table_name_gid_seq", allocationSize=1, initialValue=1)
    private $gid;

     * @var MULTIPOLYGON
     * @ORM\Column(name="geom", type="geometry", options={"geometry_type"="MULTIPOLYGON", "srid"=3795}, nullable=true)
    private $geom;

I tried to follow this solution in github to no avail, although it was exactly my situation.

Any help and insights appreciated.


So to me it looks like you have the right datatype in postgres but not inside of your source data. The doc for that library says this:

There are 2 options you can set to define the geometry. geometry_type This defines the type of the geometry, like POINT, LINESTRING etc. If you omit this option, the generic type GEOMETRY is used.

The error you're getting is indicating that it's reading type 'geometry' out of your source table but can't convert the postGres column into geometry(not the other way around). Remake your source data with the same geometry_type flag before trying to move it into postgres. This should fix your problem.

xml file in :Resources/config/doctrine/TableName.orm.xml was stale. Had been generated without geometry_type option and was not being updated when new import code was run. Deleting xml and rerunning import resolved issue.

  • when you say source data and source table, do you mean my php class? also yes, I know it's the postgres column the one "doctrine:schema:update" "--force" can't convert into geometry, the point is WHY does it want to convert it to geometry when I (following the docs) included options={"geometry_type"="MULTIPOLYGON", "srid"=3795} in my geom property declaration, stating that it should be of type MULTIPOLYGON, not the default geometry? do you understand my predicament? – Scaramouche Apr 20 '18 at 19:04
  • It's wanting to convert to type geometry becuase the first feature it reads out of your class is type 'Geometry' not type 'Polygon'. You need that options flag on your import of the data into the class, not on the call to postgres. – Brian W. Apr 20 '18 at 19:11
  • I'm really sorry, that last comment completely lost me. when you say You need that options flag on both your import and your export, you mean I should/can use options={"geometry_type"="MULTIPOLYGON", "srid"=3795} when creating a class from the table structure via doctrine:mapping:import and doctrine:mapping:convert? – Scaramouche Apr 20 '18 at 19:18
  • Sorry. Misunderstood what was going on. appologies. Have you tried php app/console doctrine:cache:clear-metadata. It seems like you have some stale info about whats in that class. – Brian W. Apr 20 '18 at 19:19
  • just did, no good :( – Scaramouche Apr 20 '18 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.