在创建新的postgres数据库并加载必要的postgis扩展之后
$ createdb demodb
$ psql demodb
> CREATE EXTENSION postgis;
> CREATE EXTENSION postgis_topology;
我在运行djangomanage.py migrate
时引发了django.db.utils.ProgrammingError: type "geometry" does not exist
异常
在这之后,我尝试在pgadmin中运行失败的查询,结果是相同的:type "geometry" does not exist
虽然在查询之前追加CREATE EXTENSION postgis;
似乎可以解决这个问题,并且查询返回ok。但是再次运行manage.py migrate
也抛出了相同的异常。在
加载新的扩展不是永久的吗?如果是这样的话,我如何永久加载它,以便在运行migrate
时加载它?在
CREATE EXTENSION
对于运行它的数据库是永久的。它以给定(或当前默认)模式创建对象。Per documentation:检查
psql
中涉及哪些架构:所使用的架构必须在当前的^{} 中(否则您必须对所有引用进行架构限定)。
我不确定
migrate
是否包含其他模式或扩展。 这很可能是search_path
的问题我需要授予数据库用户访问postgis模式的权限。我在连接到django数据库时运行了以下代码,然后migrate能够成功运行。在
GRANT ALL PRIVILEGES ON SCHEMA postgis TO username;
对我来说
grant usage on schema <postgis-install-schema> to <myschema>
解决了这个问题(<postgis-install-schema>
在我的例子中是public
)。在(TechnoConserve中建议的
grant all privileges
出于安全原因可能太多)相关问题 更多 >
编程相关推荐