【问题标题】:sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) function st_geogfromtext(unknown) does not existsqlalchemy.exc.ProgrammingError:(psycopg2.ProgrammingError)函数st_geogfromtext(未知)不存在
【发布时间】:2019-07-08 18:56:42
【问题描述】:

我正在尝试使用 geoalchemy2 和 sqlalchemy 创建一个包含地理数据的表,遵循geoalchemy ORM tutorial

我在我使用的架构上安装了 postgis 扩展。我正在连接的用户是架构的所有者

当我运行 python 代码时:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from geoalchemy2 import Geography
import src.config as config

Base = declarative_base()

class Lake(Base):
    __tablename__ = 'lake'
    __table_args__ = ({'schema': 'geobox'})
    id = Column(Integer, primary_key=True)
    country_iso_code = Column(String(2))
    zone_code = Column(String(45))
    zone_type = Column(String(45))
    zone_test = Column(Geography('POINT'))

from sqlalchemy import create_engine
engine = create_engine('postgres://{user}:{pwd}@{host}:{port}/{database}'.format(
    user=config.DbConfig().username,
    pwd=config.DbConfig().password,
    host=config.DbConfig().host,
    port=config.DbConfig().port,
    database=config.DbConfig().database), echo=True)

Lake.__table__.create(engine)

我得到错误:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) type "geography" does not exist

我在这里错过了什么?

【问题讨论】:

    标签: postgresql sqlalchemy postgis


    【解决方案1】:

    我发现 search_path 设置不正确,因为 postgis 已安装在表级别而不是架构级别。

    那么与 sqlalchemy 无关。我只需要更改 search_path 以让 pg 找到安装 postgis 的表:

    ALTER ROLE "my_role_name" SET search_path TO 'my_table_name',"$user",public;
    

    (假设 my_table_name 是安装了 postgis 扩展的表的名称)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 2013-05-06
      • 2016-10-19
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      相关资源
      最近更新 更多