python - CREATE EXTENSION postgis 后类型几何不存在

标签 python django postgresql postgis django-oscar

创建新的 postgres 数据库并加载必要的 postgis 扩展后

$ createdb  demodb
$ psql demodb
> CREATE EXTENSION postgis;
> CREATE EXTENSION postgis_topology;

我在运行 django manage.py migrate 时收到 django.db.utils.ProgrammingError: type "geometry"does not exist 异常抛出

在此之后,我尝试在 pgadmin 中运行失败的查询,它说同样的话:type "geometry"does not exist

尽管在查询之前附加 CREATE EXTENSION postgis; 似乎可以解决此问题并且查询返回正常。但是再次运行 manage.py migrate 抛出了同样的异常。

加载新扩展不是永久的吗?如果是这样,我如何才能永久加载它,以便在运行 migrate 时加载它?

最佳答案

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*

使用的模式必须在您当前的 search_path 中(或者您必须对所有引用进行架构限定)。
我不确定 migrate 是否包含额外的架构或扩展。 这很可能是 search_path

的问题

关于python - CREATE EXTENSION postgis 后类型几何不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25286258/

相关文章:

python - 确认浏览器预取导致删除

sql - 在 postgres 中获取 Time from now() 函数

python - 使用 Flask 无法加载 CSS

python - 如何在 sqlalchemy ORM 中进行批量更新

python - 使用最新的 Graphite 烯和 Graphite 烯-django版本时导入(无法从 'ResolveInfo' 导入名称 'graphql' )错误

postgresql - "("或附近的语法错误 COPY FROM WITH (FORMAT csv, DELIMITER E'\t', QUOTE '*', HEADER false, ENCODING 'UTF8')

php - 通过分配 "-"值返回所有行包括不存在的行

python - numpy 的 fromfile count 参数如何工作?

python - 索引错误: list index out of range

python - 我应该在哪里放置配置详细信息? [Python]