1

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?

4

1 回答 1

0

我的错,我错过了前一行的括号。在您发布哈哈之前,请确保您的括号像 () 一样关闭。

于 2019-01-26T00:02:32.910 回答