我整天试图解决这个问题。我的代码如下所示。实际上,我在Pgadmin4中创建了表。我创建了具有10列的id字段为varchar(20)数据类型的表“ atmpokhara”。之后,我从atmpokhara表中删除了ID。我将此表渲染为Django模型
python manage.py inspectdb > models.py
所有行已在表中。一切进展顺利,但是当我尝试在管理面板中打开表格时,出现以下错误:
operator does not exist: character varying = bigint
LINE 1: ...number" FROM "atmpokhara" WHERE "atmpokhara"."id" = 57173664...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Request Method: GET
Request URL: http://localhost:8000/admin/webmap/atmpokhara/5717366409/change/
Django Version: 2.1.7
Exception Type: ProgrammingError
Exception Value:
operator does not exist: character varying = bigint
LINE 1: ...number" FROM "atmpokhara" WHERE "atmpokhara"."id" = 57173664...
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Exception Location: D:\coding time\Django+ GeoDjango\Django Enviroment\venv\lib\site-packages\django\db\backends\utils.py in _execute, line 85
Python Executable: D:\coding time\Django+ GeoDjango\Django Enviroment\venv\Scripts\python.exe
Python Version: 3.7.2
Python Path:
['C:\\Users\\Tekson\\Desktop\\Web-GIS-Django\\Project',
'C:\\Program Files\\Hexagon\\ERDAS IMAGINE '
'2015\\usr\\lib\\Win32Release\\python',
'C:\\Users\\Tekson\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
'C:\\Users\\Tekson\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',
'C:\\Users\\Tekson\\AppData\\Local\\Programs\\Python\\Python37\\lib',
'C:\\Users\\Tekson\\AppData\\Local\\Programs\\Python\\Python37',
'D:\\coding time\\Django+ GeoDjango\\Django Enviroment\\venv',
'D:\\coding time\\Django+ GeoDjango\\Django '
'Enviroment\\venv\\lib\\site-packages']
Server time: Tue, 16 Jul 2019 12:23:38 +0000
请帮助我找出解决方案。
models.py文件
from django.contrib.gis.db import models as gis_models
# Create your models here.
class point(models.Model):
title = models.CharField(max_length=30)
location = gis_models.PointField(srid=4326)
def __str__(self):
return self.title
class Atmpokhara(models.Model):
bankname = models.CharField(max_length=150, blank=True, null=True)
nepalibankname = models.CharField(max_length=150, blank=True, null=True)
address = models.CharField(max_length=150, blank=True, null=True)
email = models.CharField(max_length=50, blank=True, null=True)
banktype = models.CharField(max_length=30, blank=True, null=True)
source = models.CharField(max_length=50, blank=True, null=True)
operator = models.CharField(max_length=150, blank=True, null=True)
geom = gis_models.PointField(blank=True, null=True)
phonenumber = models.CharField(max_length=50, blank=True, null=True)
class Meta:
managed = False
db_table = 'atmpokhara'
我的admin.py文件:
from .models import point,Atmpokhara
from leaflet.admin import LeafletGeoAdmin
# Register your models here.
class pointsAdmin(LeafletGeoAdmin):
list_display = ('title', 'location')
class AtmpokharaAdmin(LeafletGeoAdmin):
list_display = ('bankname', 'address', 'banktype')
admin.site.register(point,pointsAdmin)
admin.site.register(Atmpokhara, AtmpokharaAdmin)
我的views.py:
from django.core.serializers import serialize
from django.http import HttpResponse
from .models import Atmpokhara
# Create your views here.
def index(request):
return render(request, 'pages/index.html')
def atm(request):
atmData = serialize('geojson', Atmpokhara.objects.all())
return HttpResponse(atmData, content_type='json')
我的url.py文件:
from . import views
urlpatterns = [
path('', views.index, name='webmap'),
path('data/atm', views.atm, name= 'atm'),
]