postgresql Postgis / Geodjango:无法确定数据库的 PostGIS 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7491798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgis / Geodjango: Cannot determine PostGIS version for database
提问by Matt Hampel
I'm attempting to launch a GeoDjango app. I've installed Postgres & PostGIS using brew on Lion. I created a database using template_postgis: createdb -T template_postgis test
.
我正在尝试启动 GeoDjango 应用程序。我已经在 Lion 上使用 brew 安装了 Postgres 和 PostGIS。我使用 template_postgis: 创建了一个数据库createdb -T template_postgis test
。
When I run python manage.py syncdb
, I get the following error:
当我运行时python manage.py syncdb
,出现以下错误:
django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "test". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?
django.core.exceptions.ImproperlyConfigured:无法确定数据库“test”的 PostGIS 版本。GeoDjango 至少需要 PostGIS 1.3 版。数据库是从空间数据库模板创建的吗?
How can I track down the source of the error? I've checked that the user & pass in the config have access to the database etc.
如何追踪错误的来源?我已经检查过配置中的用户和传递是否可以访问数据库等。
采纳答案by ivy
As a first debugging step: try to check the postgis template version manually, e.g. on the command-line connect to your database with psql test
, and query with select postgis_lib_version();
. This function should be defined in template_postgis and return some number. Example output:
作为第一个调试步骤:尝试手动检查 postgis 模板版本,例如在命令行中使用 连接到您的数据库psql test
,并使用 进行查询select postgis_lib_version();
。这个函数应该在 template_postgis 中定义并返回一些数字。示例输出:
$ psql test
psql (9.0.4)
Type "help" for help.
test=# select postgis_lib_version();
postgis_lib_version
---------------------
1.5.2
(1 row)
If an error occurs, you know the error is in the database.
如果发生错误,您就知道错误在数据库中。
回答by David
Just add in your settings.py your right version of postgis :
只需在您的 settings.py 中添加您正确版本的 postgis :
POSTGIS_VERSION = (2, 0, 3)
POSTGIS_VERSION = (2, 0, 3)
回答by Zags
The solution for me was to run the following in the postgres terminal:
我的解决方案是在 postgres 终端中运行以下命令:
psql database_name
database_name=# CREATE EXTENSION postgis;
If you get ERROR: relation "spatial_ref_sys" already exists
, run the following before CREATE EXTENSION postgis
:
如果你得到了ERROR: relation "spatial_ref_sys" already exists
,请先运行以下命令CREATE EXTENSION postgis
:
drop table spatial_ref_sys;
drop table geometry_columns;
回答by Rmatt
And in case the previous select returns an error, it may be that one particular version of PostGIS was installed on that database, that you updated Postgres.app to a newer version, that bundles a newer version of PostGIS. For example, after the recent update from Postgis 2.0 to 2.1
如果之前的选择返回错误,则可能是在该数据库上安装了一个特定版本的 PostGIS,您将 Postgres.app 更新为较新版本,该版本捆绑了较新版本的 PostGIS。例如,最近从 Postgis 2.0 更新到 2.1 之后
In that case, you can make a migration after copying back some libraries, like described in this ticket
在这种情况下,你可以复制回一些库后进行迁移,就像在描述这张票
回答by whale_steward
if you are using django_debug_toolbar
try to delete it or comment out debug_toolbar/utils/tracking/db.py
line 152 as suggested on https://github.com/django-debug-toolbar/django-debug-toolbar/issues/442
如果您正在使用,请按照https://github.com/django-debug-toolbar/django-debug-toolbar/issues/442 上的建议django_debug_toolbar
尝试删除它或注释掉debug_toolbar/utils/tracking/db.py
第 152 行