问题
After creating new postgres db and loading necessary postgis extension
$ createdb demodb
$ psql demodb
> CREATE EXTENSION postgis;
> CREATE EXTENSION postgis_topology;
I get django.db.utils.ProgrammingError: type "geometry" does not exist
exception thrown while running django manage.py migrate
After this I tried running the failed query in pgadmin and it said the same: type "geometry" does not exist
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.
Isn't loading new extension permanent? And if so, how can I load it permanently, so it is loaded when running migrate
?
回答1:
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:
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.
Check which schemas are involved in psql
:
\connect mydb
\x
\dx postgis*
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
回答2:
I needed to give my database user permission to access the postgis schema. I ran the following while connected to my django database and then migrate was able to run successfully.
GRANT ALL PRIVILEGES ON SCHEMA postgis TO username;
回答3:
For me grant usage on schema <postgis-install-schema> to <myschema>
solved it (<postgis-install-schema>
was public
in my case).
(grant all privileges
as suggested from TechnoConserve may be too much for security reasons)
来源:https://stackoverflow.com/questions/25286258/type-geometry-does-not-exist-after-create-extension-postgis