问题描述
创建新的postgres数据库并加载必要的postgis扩展
After creating new postgres db and loading necessary postgis extension
$ createdb demodb
$ psql demodb
> CREATE EXTENSION postgis;
> CREATE EXTENSION postgis_topology;
运行Django manage.py migrate
此后,我尝试在pgadmin中运行失败的查询,并说相同的内容:type "geometry" does not exist
After this I tried running the failed query in pgadmin and it said the same: type "geometry" does not exist
尽管在查询之前添加CREATE EXTENSION postgis;
似乎可以解决此问题,但查询返回的结果还可以.但是再次运行manage.py migrate
会引发相同的异常.
Although appending CREATE EXTENSION postgis;
before the query seems to fix this and query returned ok. But running manage.py migrate
again throwed the same exception.
不是要永久加载新的扩展程序吗?如果是这样,我如何永久加载它,以便在运行migrate
时加载它?
Isn't loading new extension permanent? And if so, how can I load it permanently, so it is loaded when running migrate
?
推荐答案
CREATE EXTENSION
是永久.它将在给定(或当前默认值)中创建对象模式. 每个文档:
CREATE EXTENSION
is permanent for the database you are running it in. It creates objects in a given (or the current default) schema. Per documentation:
假设扩展允许其内容重定位,则在其中安装扩展对象的模式的名称. 命名架构必须已经存在.如果未指定,则 扩展的控制文件也未指定架构,当前 使用默认的对象创建模式.
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
The schemas used must be in your current search_path
(or you'd have to schema-qualify all references).
I am not sure migrate
includes additional schemas or extensions at all.Most probably, this is an issue with the search_path
这篇关于CREATE EXTENSION postgis之后不存在类型几何体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!