首页 > 解决方案 > 致命:数据库“postgres”不存在无法创建“test_app_development”数据库。请检查您的配置

问题描述

当我手动创建数据库并尝试使用它们时,例如:rake db:create我收到以下错误:

FATAL:  database "postgres" does not exist
Couldn't create 'test_app_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "postgres" does not exist

Caused by:
PG::ConnectionBad: FATAL:  database "postgres" does not exist

Tasks: TOP => db:create
(See full trace by running task with --trace)

我有另一个数据库rails_articles_development,它运行良好,但我无法创建新数据库

这是我的 Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.1'

gem 'rails', '~> 6.1.3', '>= 6.1.3.1'
# gem 'sqlite3', '~> 1.4'
gem 'pg'
gem 'bootsnap', '>= 1.4.4', require: false
gem 'jbuilder', '~> 2.7'
gem 'puma', '~> 5.0'
gem 'sass-rails', '>= 6'
gem 'turbolinks', '~> 5'
gem 'webpacker', '~> 5.0'

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'listen', '~> 3.3'
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'spring'
  gem 'web-console', '>= 4.1.0'
end

group :test do
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  gem 'webdrivers'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

这是我的 database.yml

default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: test_app_development

test:
  <<: *default
  database: test_app_test

production:
  <<: *default
  database: test_app_production

我的 Linux 机器上已经运行了 postgresql

psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)

template1=# \l
                                          List of databases
            Name            |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
----------------------------+----------+----------+-------------+-------------+-----------------------
 rails_articles_development | akash    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0                  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                            |          |          |             |             | postgres=CTc/postgres
 template1                  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                            |          |          |             |             | postgres=CTc/postgres
(3 rows)

这是我的数据库用户

                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 akash     | Superuser                                                  | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 rc        | Superuser, Create role, Create DB                          | {}

我无法理解具体问题在哪里。我是 postgresql 的菜鸟。所有帮助表示赞赏。

标签: ruby-on-railspostgresql

解决方案


推荐阅读