type modifier is not allowed for type "geometry" when updating DB with postgis via geoalchemy2 & alembic

1.2k Views Asked by At

My alembic update script for adding a new postgis geometry point looks like this:

from alembic import op
import sqlalchemy as sa
import geoalchemy2 as ga

def upgrade():
    op.add_column('stuff', sa.Column('my_location', ga.Geometry('POINT', management=True)))


def downgrade():
    pass

When I run the script via

alembic upgrade head

the following error occurs

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) type modifier is not allowed for type "geometry"
LINE 1: ALTER TABLE events ADD COLUMN location geometry(POINT,-1)

I am using postgres 9.1, postgis 1.5, sqlalchemy 1.0.9, geoalchemy2 0.2.6.

1

There are 1 best solutions below

0
On

You are using Postgis 1.5, which does not support type modifier for the geometry type.

How to fix the issue: Postgis 1.5 is currently quite old, so upgrade to Postgis 2.x

If for same reason you cannot upgrade your Postgis installation, the correct way to add a geometry column is using the function AddGeometryColumn(). The SQL statement looks so:

SELECT AddGeometryColumn ('public','events','geom',0,'POINT',2);

where the arguments mean:

1) schema name, 2) table name, 3) column name, 4) srid, 5) type, 6) dimension.

However you are already using the correct flag for adding geometry column in Postgis 1.5: management=True. In accordance to to documentation, this should force SqlAlchemy to use the AddGeometryColumn() syntax. Maybe the error is coming from Alembic an not from GeoAlchemy?