[英]I am adding location field in my django model Its showing an error
當我嘗試遷移它時,我試圖在 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"
我只是想在我的服務模型中成功添加位置字段提前謝謝
你的 postgres DB 缺少 postgis 插件
請使用以下命令安裝 postgis 擴展
sudo apt-get install postgis postgresql-9.3-postgis-scripts
請使用與您的 postgres db 相同的 postgis 版本
sudo apt-get install postgis postgresql-11-postgis-scripts
給了我:
The following packages have unmet dependencies:
postgis : Depends: libgdal20 (>= 2.0.1) but it is not installable
Depends: libproj12 (>= 4.9.0) but it is not installable
Recommends: postgresql-postgis
Recommends: postgis-doc but it is not going to be installed
然后,我嘗試成功:
sudo apt-get install postgresql-11-postgis-2.5-scripts
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.