Search code examples
pythonpostgresqlsqlalchemypostgisgeoalchemy

SQLAlchemy: create_engine() syntax error with PostGIS


currently I am trying to create a postGIS database with sqlalchemy. I plan on normalizing my database by making several tables for shapefile data to be uploaded. my code is as follows:

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, BigInteger, DateTime, MetaData
from geoalchemy2 import Geometry

Base = declarative_base()

class meta_link(Base):
    __tablename__ = 'META_LINK'
    ID = Column(BigInteger, primary_key = True)
    FARM = Column(String)
    FIELD = Column(String)
    YEAR = Column(Integer)
    CROP = Column(String)
    TYPE = Column(String)
    TIMESTAMP = Column(DateTime, default=datetime.datetime.utcnow)

I also inserted some other tables, but I made them exactly like the one listed above. Currently I am trying to create the tables by doing the following:

engine = create_engine('postgresql://myusername:mypassword@localhost:5432/my databasename')

metadata = MetaData()

metadata.create_all(bind=engine)

When I try to run the python script I get the following error:

  File "./app.py", line 83
    engine = create_engine('postgresql://postgres:postgresql@localhost:5432/ammar_DIFM_database')
         ^
SyntaxError: invalid syntax

I am currently trying to discover my bug, yet I cannot seem to figure it out. I also tried adding "echo=true" at the end of the create_engine statement, yet it did not work. How do I fix this syntax error?


Solution

  • My bad, I missed a parenthesis on the previous line. make sure your parenthesis are closed like () before you post haha.