Postgres 13.2 on rails 5.2.4.1: ActiveRecord::NoDatabaseError: FATAL: database * does not exist on rake db:create
Postgres 13.2 on rails 5.2.4.1: ActiveRecord::NoDatabaseError: FATAL: database * does not exist on rake db:create
我正在尝试在我的本地 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
您可以改用此命令创建数据库。
在您的终端中:createdb {DB_NAME}
在您的情况下它将是 createdb scholarden_development
我正在尝试在我的本地 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
您可以改用此命令创建数据库。
在您的终端中:createdb {DB_NAME}
在您的情况下它将是 createdb scholarden_development