Inserting POINT Geometry from DJANGO to POSTGIS database error

345 Views Asked by At

Hello I try to use DJANGO to insert point clicked on Leaflet in a POSTGIS database. During the import I receive the following error : "function st_geomfromewkb(bytea) does not exist"

My understanding is that the ST_GeomFromEWKB is used to insert binary representation od geometry, and this is quite weird here because what I intend to do is inserting a wkb object.

my view is defined as bellow:

from django.contrib.gis.geos import Point
def add_site(request):

if(request.method == 'POST'):
    
    site_name = request.POST.get('site_name')
    customer_name = request.POST.get('customer_name')
    lat = str(request.POST.get('lat'))
    lng = str(request.POST.get('lng'))
    point = Point(lng,lat,srid=4326).wkb
    logger.info(type(point))
    insert = customers_sites(site_name=site_name,customer_name=customer_name,geom=point)
    
    insert.save()

Any idea of what is wrong here ?? Thank you for your help !

1

There are 1 best solutions below

0
adeel khalilahmad On

Add PostGIS extension into your database by running this query. Remember that only PostGIS installation will not work until you add the PostGIS extension into the database. connect to your database and execute the following Query.

-- Enable PostGIS (as of 3.0 contains just geometry/geography)
CREATE EXTENSION postgis;