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.

1 Answer 1


To me it looks like you have the right datatype in PostgreSQL but not inside of your source data. The documentation 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 PostgreSQL column into geometry (not the other way around). Remake your source data with the same geometry_type flag before trying to move it into PostgreSQL . This should fix your problem.

From comments it appears that the xml file in :Resources/config/doctrine/TableName.orm.xml was stale. It had been generated without geometry_type option and was not being updated when new import code was run. Deleting the xml and rerunning import resolved the issue.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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