3

I have installed all the dependies of Geodjango! Now i am following its tutorial https://docs.djangoproject.com/en/1.2/ref/contrib/gis/tutorial/ -- Problem: command python manage.py syncdb generates error at mpoly geometry(multipolygon 4326) not null that geometry does not exist

from django.contrib.gis.db import models

class WorldBorders(models.Model):
    # Regular Django fields corresponding to the attributes in the
    # world borders shapefile.
    name = models.CharField(max_length=50)
    area = models.IntegerField()
    pop2005 = models.IntegerField('Population 2005')
    fips = models.CharField('FIPS Code', max_length=2)
    iso2 = models.CharField('2 Digit ISO', max_length=2)
    iso3 = models.CharField('3 Digit ISO', max_length=3)
    un = models.IntegerField('United Nations Code')
    region = models.IntegerField('Region Code')
    subregion = models.IntegerField('Sub-Region Code')
    lon = models.FloatField()
    lat = models.FloatField()

    # GeoDjango-specific: a geometry field (MultiPolygonField), and
    # overriding the default manager with a GeoManager instance.
    mpoly = models.MultiPolygonField() //ERROR HERE

How to solve this error?

UPDATE:

python manage.py sqlall world generates following output:

BEGIN;
CREATE TABLE "world_worldborders" (
    "id" serial NOT NULL PRIMARY KEY,
    "name" varchar(50) NOT NULL,
    "area" integer NOT NULL,
    "pop2005" integer NOT NULL,
    "fips" varchar(2) NOT NULL,
    "iso2" varchar(2) NOT NULL,
    "iso3" varchar(3) NOT NULL,
    "un" integer NOT NULL,
    "region" integer NOT NULL,
    "subregion" integer NOT NULL,
    "lon" double precision NOT NULL,
    "lat" double precision NOT NULL,
    "mpoly" geometry(MULTIPOLYGON,4326) NOT NULL
)
;
CREATE INDEX "world_worldborders_mpoly_id" ON "world_worldborders" USING GIST ( "mpoly" );

COMMIT;

and python manage.py syncdb generates: Program Error Geometry Doesn't exist :

root@cvp-linux:~/geodjango# python manage.py syncdb Syncing... Creating tables ... Creating table django_admin_log Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_groups Creating table auth_user_user_permissions Creating table auth_user Creating table django_content_type Creating table django_session Creating table world_worldborders Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle return self.handle_noargs(**options) File "/usr/local/lib/python2.7/dist-packages/south/management/commands/syncdb.py", line 92, in handle_noargs syncdb.Command().execute(**options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle return self.handle_noargs(**options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 107, in handle_noargs cursor.execute(statement) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 69, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 53, in execute return self.cursor.execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 51, in execute return self.cursor.execute(sql) django.db.utils.ProgrammingError: type "geometry" does not exist LINE 14: "mpoly" geometry(MULTIPOLYGON,4326) NOT NULL

Tameen Malik
  • 1,258
  • 6
  • 17
  • 45

4 Answers4

5

A couple of things to check for:

  • You've run CREATE EXTENSION postgis;
  • The GEOS_LIBRARY_PATH is set in your project's settings.py file

This second point gave me some trouble, though it was the first that did the trick finally. I'm running this on Cygwin 64 bit, so there's a bit of extra work to do to make it work. If you're not running in the Cygwin environment, most likely the file you're looking for is libgeos_c.so; I needed to point it to cyggeos_c-1.dll (still running on Windows, so the .dll extension is what I needed to find).

I was positive that I had run the CREATE EXTENSION command already, but I may not have run it in the Cygwin environment. Or I had tried, but had failed to remember that I have a nightmare of a configuration such that the postgres server is not running on localhost, so I was avoiding psql. Such is my own brand of thickness.

foszter
  • 179
  • 1
  • 11
0

Here is the fixed ticket,

https://code.djangoproject.com/ticket/21547

Updated GeoDjango tutorial with PostGIS 2 output

dhana
  • 6,487
  • 4
  • 40
  • 63
  • Before posting question here i read this but I don't understand that ticket. can you please explain the steps to solve this problem? – Tameen Malik May 06 '14 at 10:18
  • Try this `python manage.py sqlall world` and post the output in your question – dhana May 06 '14 at 10:27
  • `django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "geodjango". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?` @dhana ` – Tameen Malik May 06 '14 at 10:58
  • 1
    check this http://stackoverflow.com/questions/7491798/postgis-geodjango-cannot-determine-postgis-version-for-database – dhana May 06 '14 at 11:17
  • check the minimum requirements https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#spatial-database – dhana May 06 '14 at 11:19
  • add this `GEOS_LIBRARY_PATH = '/home/bob/local/lib/libgeos_c.so'` in your settings.py file here refrence link https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/geolibs/#can-t-find-geos-library – dhana May 06 '14 at 11:36
  • No @dhana It's again generating program error : `django.db.utils.ProgrammingError: type "geometry" does not exist LINE 14: "mpoly" geometry(MULTIPOLYGON,4326) NOT NULL` – Tameen Malik May 08 '14 at 05:12
0

In my case the issue was that the commands:

-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
-- Enable Topology
CREATE EXTENSION postgis_topology;
-- fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
-- Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;

shoudl be run in context of certain database, so you need to connect to your_db first:

\connect your_db

and then run above!

andilabs
  • 22,159
  • 14
  • 114
  • 151
0

try adding

objects = models.GeoManager()

after mpoly in your models.py

jcs
  • 426
  • 3
  • 14