我在我的django模型中添加位置字段它显示错误

问题描述 投票:0回答:1

我试图在我尝试迁移它时,在postgis扩展的帮助下向我的django模型添加一个位置字段,错误显示:

django.db.utils.OperationalError:无法打开扩展控制文件“/usr/share/postgresql/10/extension/postgis.control”:没有这样的文件或目录

我已经更新了我的settings.py

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'meenfee',
    'accounts',
    'rest_framework',
    'rest_auth',
    'rest_auth.registration',
    'django.contrib.sites',
    'allauth',
    'django.contrib.gis',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'allauth.socialaccount.providers.google',
    'django.contrib.admin',
]


 DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'meenfeefinal',
        'USER': 'meenfeefinaluser',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '',
    }
}

这是我的models.py。看看位置字段

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




class Service(models.Model):



    user                    = models.ForeignKey(User, on_delete=models.CASCADE)
    service_name            = models.CharField(max_length=200,null=True,default="sample service")
    category                = models.ForeignKey(Category, on_delete=models.CASCADE)  
    subcategory             = models.ForeignKey(SubCategory,on_delete=models.CASCADE)
    experience              = models.TextField(blank=True,null=True)
    levelskill              = models.CharField(max_length=120, choices=LEVELSKILLS)
    service_place           = models.CharField(max_length=120, choices=LOCATION)
    location                = gis_models.PointField(u'longitude/latitude',geography=True, blank=True, null=True)
    city                    = models.ForeignKey(City,blank=True,null=True,on_delete=models.DO_NOTHING)
    distance_limit          = models.CharField(max_length=100, choices=DISTANCE)
    service_pricing         = models.PositiveIntegerField(help_text='in Jordanian dinar')
    pricing_timing_unit     = models.CharField(max_length=30,choices=PRICINGUNIT)
    quote_at_request        = models.BooleanField(default=False, help_text='This will create popup when they accept a requester request')
    provide_tools           = models.BooleanField(default=True)
    tool_specify            = models.TextField(blank =True, null=True)
    instant_booking         = models.BooleanField(default =True)
    avg_rating              = models.FloatField(default=0.0)
    created                 = models.DateTimeField(auto_now_add=True)

    def __int__(self):
        return self.id

    class Meta:
        verbose_name_plural = "Services"

我只是想在我的服务模型中成功添加位置字段,提前谢谢

python django python-3.x postgresql postgis
1个回答
0
投票

你的postgres数据库缺少postgis插件

请使用以下命令安装postgis扩展

sudo apt-get install postgis postgresql-9.3-postgis-scripts

请使用与postgres db相同的postgis版本

© www.soinside.com 2019 - 2024. All rights reserved.