创建扩展postgis后,类型几何图形不存在

2024-09-20 07:06:28 发布

您现在位置:Python中文网/ 问答频道 /正文

在创建新的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时加载它?在


Tags: py数据库typecreateextensionnotpostgresmigrate
3条回答

CREATE EXTENSION对于运行它的数据库是永久的。它以给定(或当前默认)模式创建对象。Per documentation:

schema_name

The name of the schema in which to install the extension's objects, given that the extension allows its contents to be relocated. The named schema must already exist. If not specified, and the extension's control file does not specify a schema either, the current default object creation schema is used.

Remember that the extension itself is not considered to be within any schema: extensions have unqualified names that must be unique database-wide. But objects belonging to the extension can be within schemas.

检查psql中涉及哪些架构:

\connect mydb
\x 
\dx postgis*

所使用的架构必须在当前的^{}中(否则您必须对所有引用进行架构限定)。
我不确定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出于安全原因可能太多)

相关问题 更多 >