【发布时间】:2021-10-09 12:21:51
【问题描述】:
我尝试从 Windows 本地计算机连接到 gcp postresql SQL-server 中的数据库。我连接了这样的命令:
cloud_sql_proxy -instances=<myProject:us-central1:myInstance>=tcp:0.0.0.0:8080
&
psql -U postgres -h <Public IP address>
现在我需要使用sqlalchemy 创建数据库。
我试过了
app.config["SQLALCHEMY_DATABASE_URI"] = 'postgres+psycopg2://<db_user>:<db_pass>@<Public IP address>/<myInstance>?host=<myProject:us-central1:myInstance>'
在命令flask db migrate之后出现错误:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "<myProject:us-central1:myInstance>" to address: Unknown host
然后我尝试在 myProject:us-central1:myInstance 末尾创建 / 我又遇到了一个错误
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Invalid argument (0x00002726/10022)
Is the server running locally and accepting
connections on Unix domain socket "?host=<myProject:us-central1:myInstance>//.s.PGSQL.8080"?
最后我输入了.s.PGSQL.8080,得到了同样的错误:
server: Invalid argument (0x00002726/10022)
Is the server running locally and accepting
connections on Unix domain socket "?host=<myProject:us-central1:myInstance>//.s.PGSQL.8080/.s.PGSQL.8080"?
请告诉我应该如何解决我的问题?
【问题讨论】:
标签: python postgresql flask flask-sqlalchemy google-cloud-sql