0

Added a Point field in one of my model to load map.to migrate the changes in model ,in pycharm terminal python manage.py makemigrations run okay. but python manage.py migrate raise ValueError('Cannot use object with type %s for a spatial lookup parameter.' % type(obj).name) .

i think the reason could be changes in Django 2.2.I even tried using MultiPolygon field ,PointField .

settings.py

CORE_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.postgres',
    'django.contrib.gis'
]

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',

models.py

from django.contrib.gis.db import models

longitude = models.FloatField("Outlet Longitude", default=0.0, blank=False, help_text="Longitude")
    latitude = models.FloatField("Outlet Latitude", default=0.0, blank=False, help_text="Latitude")
    location = models.PointField()

i just want to load map .

4

2 回答 2

1

在我的情况下,我输入元组值作为默认值是一个问题,因此发生了错误。

  1. 删除模型的迁移文件夹中的迁移信息。
  2. 如下设置默认值。
from django.contrib.gis.geos import Point
location = gis_models.PointField(default=Point(0, 0), blank=True)
  1. python manage.py makemigrations
  2. python manage.py 迁移
于 2020-05-13T09:12:53.103 回答
0

要使用 postgis 加载地图,您可以执行以下操作:

from django.contrib.gis.db import models as gis_models

location = gis_models.PointField(
        "Location in Map", geography=True, blank=True, null=True,
        srid=4326, help_text="Point(longitude latitude)")

建议:从其他应用导入模型时尝试使用正确的别名

于 2019-07-17T09:29:32.067 回答