Postgres 13.2 on rails 5.2.4.1: ActiveRecord::NoDatabaseError: FATAL: database * does not exist on r
Posted
技术标签:
【中文标题】Postgres 13.2 on rails 5.2.4.1: ActiveRecord::NoDatabaseError: FATAL: database * does not exist on rake db:create【英文标题】: 【发布时间】:2021-03-05 07:51:47 【问题描述】:我正在尝试在本地的 macOS Catalina 10.15.7、rails 5.2.4 和 postgres 13.2 上设置项目。
但是当我尝试通过运行rake db:create
或bundle exec rake db:create
或rails db:create
创建数据库时,都会导致相同的错误。
错误日志:
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "scholarden_development" does not exist
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:696:in `rescue in connect'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:691:in `connect'....
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:22:in `eval'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:22:in `<main>'
Caused by:
PG::ConnectionBad: FATAL: database "scholarden_development" does not exist
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/gems/pg-0.21.0/lib/pg.rb:56:in `initialize'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/gems/pg-0.21.0/lib/pg.rb:56:in `new'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/gems/pg-0.21.0/lib/pg.rb:56:in `connect'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
......5.2.4.1/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:22:in `eval'
/Users/saqibshahzad/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:22:in `<main>'
Tasks: TOP => db:create => db:load_config => environment
我的database.yml
:
default: &default
adapter: postgresql
encoding: unicode
template: template0
pool: <%= ENV.fetch("RAILS_MAX_THREADS") 5 %>
development:
<<: *default
database: scholarden_development
host: localhost
port: 5432
username: rails_dev
password: password
production:
<<: *default
database: scholarden_production
host: localhost
port: 5432
【问题讨论】:
你能发布你的 postgres 日志吗?您收到此错误的原因可能是缺少数据库角色,甚至可能是导轨预加载了您的代码并引发了此错误。更多信息here 运行createdb scholarden_development
时会发生什么?另外,你是安装了 OSX 的 Postgres 包,还是运行了brew install postgresql
?
【参考方案1】:
您可以通过此命令创建数据库。
在您的终端中:createdb DB_NAME
在您的情况下它将是 createdb scholarden_development
【讨论】:
是的,我已经用同样的命令创建了它。不过谢谢以上是关于Postgres 13.2 on rails 5.2.4.1: ActiveRecord::NoDatabaseError: FATAL: database * does not exist on r的主要内容,如果未能解决你的问题,请参考以下文章
你好 postgres 数据库连接错误 Ruby on rails
遇到致命问题:使用 ruby on rails 对用户“postgres”进行对等身份验证失败
Ruby On Rails Heroku Postgres数据库SSL连接
尝试从 Ruby on Rails 连接到 postgres(在 docker 容器中)