创建新的 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/