我正在尝试启动一个geojango应用程序。PostGIS在Lion上使用brew。我使用template_postgis创建了一个数据库:createdb -T template_postgis test
.
当我运行python manage.py syncdb
时,我得到以下错误:
django.core.exceptions。ImproperlyConfigured:无法确定PostGIS版本为数据库"测试"。GeoDjango至少需要PostGIS版本1.3。数据库是从空间数据库创建的吗模板吗?
我怎样才能找到错误的来源?我检查了用户&
只需在settings.py中添加正确版本的postgis:
POSTGIS_VERSION = (2,0, 3)
作为调试的第一步:尝试手动检查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)
如果发生错误,您知道错误在数据库中
我的解决方案是在postgres终端中运行以下命令:
psql database_name
database_name=# CREATE EXTENSION postgis;
如果得到ERROR: relation "spatial_ref_sys" already exists
,在CREATE EXTENSION postgis
之前执行以下命令:
drop table spatial_ref_sys;
drop table geometry_columns;
如果前面的选择返回错误,则可能是该数据库上安装了特定版本的PostGIS,您更新了Postgres。应用程序的更新版本,捆绑了一个新版本的PostGIS。例如,最近从Postgis 2.0更新到2.1之后
在这种情况下,您可以在复制回一些库之后进行迁移,就像这个票据
如果您正在使用django_debug_toolbar
尝试删除它或注释出debug_toolbar/utils/tracking/db.py
行152建议https://github.com/django-debug-toolbar/django-debug-toolbar/issues/442