djangopostgresqlpostgisgeodjangopostgis-raster

django.db.utils.ProgrammingError: type "raster" does not exist


my models: I have created 3 models here and When I migrate then I get the error.

from django.contrib.gis.db import models

from django.contrib.gis.db.models.fields import RasterField

class WorldBorder(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)
    mpoly = models.MultiPolygonField()

    # Returns the string representation of the model.
    def __str__(self):
        return self.name

class Zipcode(models.Model):
    code = models.CharField(max_length=5) 
    poly= models.PolygonField()

class Elevation(models.Model):
    name = models.CharField(max_length=100,blank=True, null=True)
    rast = RasterField(srid=2346)  

my settings .. The database I used is Postgres so that I can use postgis for geodjango

DATABASES = {
"default": {
    "ENGINE": "django.contrib.gis.db.backends.postgis",
    "NAME": "django_course",
    "USER": "postgres",
    "PASSWORD": "**************",
    "HOST": "localhost",
    "PORT": "5432",
}
}

Solution

  • You are missing the PostGIS Raster extension. Create the extension and try again:

    CREATE EXTENSION postgis_raster;
    

    Quote from the documentation:

    Note that a major change in 3.0 is that the raster functionality has been broken out as a separate extension.