我有一个基本的Rails应用程序,试图在其中使用Google Cloud SQL Postgres数据库作为后端。但是,当我运行rake db:migrate
时,没有错误,也没有在我们的development
环境的GCP数据库中创建任何表。
我可以通过sql客户端登录到GCP Postgres数据库,因此我可以使用凭据。我可以通过客户端创建和删除表。
我缺少任何细节吗?我正在使用:
Rails 4.2.11.1
ruby 2.5.0p0
这是我的Gemfile和database.yml的重要内容。
# Gemfile
gem "rails", "~> 4.2.8"
group :production, :development do
gem "pg", "~> 0.21"
end
group :test do
gem "sqlite3", "~> 1.3.11"
end
# database.yml
postgres_settings: &postgres_settings
adapter: postgresql
encoding: utf8
pool: 5
username: postgres
password: <saved>
database: <saved>
socket: /cloudsql/<instance connection name>
development:
<<: *postgres_settings
production:
<<: *postgres_settings
test:
adapter: sqlite3
pool: 5
timeout: 5000
database: db/test.sqlite3
答案 0 :(得分:2)
正在读取yml文件,我可以看到在“ postgres_settings”部分中您没有设置“主机”标签。
在GitHub链接[1]中,您可以找到一个将ruby连接到postgresql的模板,这些模板是GCP“带有Ruby的Bookshelf应用程序” [2]发布的教程内的示例的一部分。
希望对您有所帮助,否则请告诉我。
[1] https://github.com/GoogleCloudPlatform/getting-started-ruby/blob/master/2-postgresql/config/database.example.yml [2] https://cloud.google.com/ruby/getting-started/tutorial-app
答案 1 :(得分:0)
尝试在迁移后执行rake db:seed
,我在heroku上确实遇到了类似的问题,这就是我可以解决的问题