ruby-on-rails - 致命:数据库“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 的菜鸟。所有帮助表示赞赏。
解决方案
推荐阅读
- r - 在函数体内捕获和评估函数参数
- visual-studio - Rider 中 Visual Studio 的刹车线
- asp.net-core - 如何在 asp.net core 的其他表中添加数据和删除相同的数据?
- javascript - 阻止用户在 Firebase 中注册?
- java - 用另一个静态成员类扩展一个静态成员类是否安全?
- c# - 如何通过将 IoC 的名称用作字符串来动态解析 IoC
- c++ - 为什么编译器不选择 `forward` 的右值引用版本?
- sql-server - 用于获取列组合的不重复数据的 SQL 语句
- android - START_STICKY 表示行为类似于服务的 Activity
- leaflet - 如何将用户名:密码传递给 Leaflet 中的基本身份验证外部 WMS