【发布时间】:2020-05-14 15:43:46
【问题描述】:
我的模型:我在这里创建了 3 个模型,当我迁移时出现错误。
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)
我的设置..我使用的数据库是 Postgres,这样我就可以将 postgis 用于 geodjango
DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": "django_course",
"USER": "postgres",
"PASSWORD": "**************",
"HOST": "localhost",
"PORT": "5432",
}
}
【问题讨论】:
-
您的数据库是否安装了
PostGIS? -
@JimJones 它确实安装了 postgis 是因为 postgres 版本的问题吗??
-
你能把你从这个函数中得到的东西贴在 postgres 中吗?
SELECT PostGIS_Version() -
@JimJones 我得到了这个 3.0 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
-
@JimJones 这完全有效。你能解释一下怎么做吗?
标签: django postgresql postgis geodjango postgis-raster