I am trying to solve this problem whole day. My code is shown below. Actually, I created my tables in Pgadmin4. I created the table "atmpokhara" having 10 columns with id field as varchar(20) datatype. After that, I drop the id filed from my atmpokhara table. I render this table to django model using
python manage.py inspectdb > models.py
All the row are already in tables. Everything is going good, but when I try to open my table inside my admin panel, I get following error:
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
Please help me to findout the solution.
models.py file
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'
my admin.py file:
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)
my 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')
my url.py file:
from . import views
urlpatterns = [
path('', views.index, name='webmap'),
path('data/atm', views.atm, name= 'atm'),
]