我对web开发是个新手,在Google Cloud方面也是新手,很抱歉。
基本上,我正在用Swift做一个应用程序的后端部分(使用Perfect),它在我的本地计算机上运行得很顺利,我正在使用一个本地Postgre数据库(在我的应用程序中使用PostgreORM )。
但是,当我将其部署到Google Cloud时,它无法识别数据库(我在计算机引擎中创建了一个相同的poster数据库和一个cloud SQL ( Google Cloud的Postgre服务,具有相同的名称和凭据),但同样,当应用程序在云上时,它无法识别数据库,我错过了什么?我怎么发动汽车呢?用Postgre安装其他docker镜像吗?
下面是我的DBConnector代码:
import PostgresStORM
func setupDBCredentials() -> PostgresConnector.Type{
let connection = PostgresConnector.self
connection.host = "localhost" // or the connection name of the Google Cloud, it doesn't work as well
connection.username = "postgres"
connection.password = "nearby"
connection.database = "nearby"
connection.port = 5432
return connection
}基本上,我如何让我的google应用程序引擎代码连接到任何数据库?
此外,如果有帮助,我正在使用Perfect Assistant将我的代码部署到Google Cloud,使用Docker。
已经谢谢你了!
发布于 2017-10-01 22:40:42
您可能需要执行一些操作才能进行连接,例如授予对Cloud SQL实例的访问权限。Here is the link to the PHP docs,它涵盖了您想要遵循的主要步骤,并显示了您还需要的连接字符串的表示。
我相信你的连接字符串应该是这样的
pgsql:dbname=DATABASE;host=/cloudsql/CONNECTION_NAME其中,CONNECTION_NAME的格式为PROJECT_ID:CLOUD_SQL_REGION_ID:CLOUD_SQL_INSTANCE_ID
https://stackoverflow.com/questions/46507662
复制相似问题