问题
I'm using Django 1.2.3, PostGIS 1.5.2.
For some reason when I run
python manage.py syncdb
it's creating all the other fields in the database from my models but avoids creating a field I named point that supposed to be a PointField.
In my model.py files I have imported:
from django.contrib.gis.db import models
and commented:
#from django.db import models
my model looks something like this:
class MyModel(models.Model):
myid = models.AutoField(primary_key=True)
title = models.CharField(max_length=50)
point = models.PointField()
objects = models.GeoManager()
Also when is creating the admin side I get the errors below:
Failed to install index for reports.MyModel model: permission denied for relation spatial_ref_sys
CONTEXT: SQL statement "SELECT SRID FROM spatial_ref_sys WHERE SRID = new_srid"
PL/pgSQL function "addgeometrycolumn" line 74 at SQL statement
SQL statement "SELECT AddGeometryColumn('','',$1,$2,$3,$4,$5)"
PL/pgSQL function "addgeometrycolumn" line 4 at SQL statement
In my setting.py I've added:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
and
INSTALLED_APPS = (
...
'django.contrib.gis',
...
Any ides why I'm heaving this issues? Thank you!
回答1:
The problem was that the PostgreSQL user role django was using had insufficient rights.
What happened when I enabled my database with the PostGIS it created a couple of tables "geometry_columns" and "spatial_ref_sys" using a different user role. So again when Django was trying to access those two tables it chocked because it didn't have enough rights.
It was that simple, whew :)
回答2:
Wanted to let you know that I was getting this error on Django 1.4.3, Postgres 9.1 and PostGIS 2. It worked after I downloaded and used the latest Django dev (1.6 alpha). There was no need for the Postgres user to be superuser. Apparently the support of PostGIS 2 is added in Django 1.5
来源:https://stackoverflow.com/questions/4737982/django-avoids-creating-pointfield-in-the-database-when-i-run-python-manage-py-sy