ruby-on-rails - rails db:create 成功,但随后给出错误
问题描述
我有一个带有 Dockerized PostgreSQL 数据库的 Rails 应用程序。当我运行rails db
orrails db:migrate
时,它工作得很好。
当我运行时rails db:create
,它的行为不同:
$ rails db:create
Created database 'my_app_development'
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Couldn't create 'my_app_test' database. Please check your configuration.
rails aborted!
ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/rails:5:in `<top (required)>'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:10:in `block in <top (required)>'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:7:in `tap'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:7:in `<top (required)>'
Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/rails:5:in `<top (required)>'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:10:in `block in <top (required)>'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:7:in `tap'
/Users/jasonswett/Documents/code/rails_application_template/my_app/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
我的怀疑是,由于某种原因rails db:create
试图连接到我的数据库127.0.0.1:5432
(可以工作),但随后又尝试在 上再次连接localhost:5432
,这将不起作用,因为localhost
不会进入我的容器,只会127.0.0.1:5432
。
再次,rails db
工作rails db:migrate
正常。当我尝试rails db:create
andrails db:drop
时,我得到了上面的错误。
有任何想法吗?
解决方案
弄清楚了。只是我的测试数据库设置错误(设置为localhost
而不是127.0.0.1
)。
推荐阅读
- kubernetes - Helm - how to set custom service port for ingress controller
- apache-kafka - On demand horizontally scaling event driven architectures
- mysql - Spring 数据反应存储库 - r2dbc 不工作
- javascript - how to call vuejs function from seperate javascript function
- jquery - Update bindings when element is updated outside angular
- excel - 功能化事件驱动的无模式用户窗体类
- javascript - 如何在搜索栏中添加 X 标签
- python - How can I detect a long touch from an item in kivymd?
- dailymotion-api - Dailymotion doesn't let me upload 10 video per day or even a week
- javascript - 如何在 JAVASCRIPT 中使用 array_push()?