Hi George,
Thanks for your reply.
Here are the steps I followed to set up the PostgresQSL:
2. Changed to my project "Dev-Instance" in "Google Cloud Platform"
3. Click on "SQL" and Clicked on "Create Instance"--> PostgreSQL
4. Entered the Instance ID
5. Entered the Region as "us-central1" and Zone "Any"
6. Taken machine as 4-cores, 20 GB of Memory, Storage type SSD, storage size 200gb
7. Choose all other option as the default option.
Then tried to access create_engine('postgresql+psycopg2://USER:PASSWORD@/DATABASE?host=/cloudsql/INSTANCE_CONNECTION_NAME')
After that, I followed all the steps in the given page step-by-step, and it works after that.
as per the given steps, I change the proxy command,
as per the documentation, the command is :
./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:5432
or
./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:5432 -credential_file=<PATH_TO_KEY_FILE> &
I used :
sudo ./cloud_sql_proxy -dir=/cloudsql -instances=<INSTANCE_CONNECTION_NAME> &
as per the documentation it is given as:
sudo export SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://<DATABASE-USER-ID>:<DATABASE-PASSWORD>@/<DATABASE-NAME>?host=/cloudsql/<INSTANCE-CONNECTION_NAME>
Did the same change in the app.yaml file.
Done the below changes in main.py
as per documentation :
db = SQLAlchemy(app)
class Visit(db.Model):
id = db.Column(db.Integer, primary_key=True)
timestamp = db.Column(db.DateTime())
user_ip = db.Column(db.String(46))
def __init__(self, timestamp, user_ip):
self.timestamp = timestamp
self.user_ip = user_ip
My code :
engine = create_engine(os.environ['SQLALCHEMY_DATABASE_URI'])
Session = sessionmaker(bind=engine)
Base = declarative_base()
class Visit(Base):
__tablename__ = "Visit"
id = Column("id",Integer, primary_key=True)
timestamp = Column("timestamp",DateTime)
user_ip = Column("user_ip",String(46))
Thanks
Binaya