pythonflasksqlalchemyalembicgeoalchemy2

Flask Alembic migration error with geoalchemy2 - invalid geometry_type


I'm trying to implement Flask-Migrate to help manage migrations, but I get an error when trying to make the migration script: "geoalchemy2.exc.ArgumentError: invalid geometry_type 'POINTZ' for dimension 2".

I have a Flask project and am using geoalchemy2 to interface with a PostGIS database. The database has some tables with PolygonZ and PointZ geometry (dimensions=3). The initial migration using Flask-Migrate via command line worked fine and generated the migration script (which was then tweaked to get working).

The models with the 3D geometry are defined as follows:

from MyProject import db
from geoalchemy2 import Geometry

class Source(db.Model):
    __tablename__ = 'source'
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer(), db.ForeignKey('project.id'))
    project = db.relationship('Project', foreign_keys=[project_id])
    category = db.Column(db.String(300))
    geometry = db.Column(Geometry(geometry_type='POINTZ', srid=4326, dimension=3))

class Building(db.Model):
    __tablename__ = 'building'
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer(), db.ForeignKey('project.id'))
    project = db.relationship('Project', foreign_keys=[project_id])
    geometry = db.Column(Geometry(geometry_type='POLYGONZ', srid=4326, dimension=3))

The migrations are done on the command line using the Flask Migrate commands.

flask db migrate

Which fails without making a script and produces this geoalchemy2 error

geoalchemy2.exc.ArgumentError: invalid geometry_type 'POINTZ' for dimension 2

I've also tried Flask-Alembic and it gives me the same geoalchemy2 error at the end, so I think it's something to do with how Alembic views geometry columns. Just not sure what.

Any advice would be appreciated. Thanks


Solution

  • Found the problem, I was using GeoAlchemy2 version 0.6.2 and this issue identified the problem which was nestled into GeoAlchemy2.

    I re-ran Flask Migrate after updating to GeoAlchemy2 version 0.6.3 and it created the migration script without crashing.