LoginSignup
meb4427
@meb4427 (えば)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

【rails】複数のデータベースが生じている?

データベースを作成して,webアプリケーションの作成の続けたい。

現在,railsを作成しようと,RailsTutorialを参考に,RSpecでwebアプリケーションを作成しようとしているところです。

Ruby:3.1.0
RubyonRails:6.0.4

その際に,

bin/rails db:create:all

を実行したところ,下記のエラーが生じました。

発生している問題・エラー

Rails couldn't infer whether you are using multiple databases from your database.yml and can't generate the tasks for the non-primary databases. If you'd like to use this feature, please simplify your ERB.
rails aborted!
Psych::BadAlias: Unknown alias: default

 「database.ymlから複数のデータベースの使用が推測されるため,rails はどちらを使用するのか推測がつかず,優先度の高くないデータベースを作成することができなかった。この設定を使いたい,ERBを簡素にしてください。」
というエラーメッセージと推測しております。
 このアプリを立ち上げる際,mySQLを用いた環境を立ち上げようと取り組みましたが,断念した経緯があります。
 しかしながら,database.ymlの記載は下記のとおりであり,複数のデータベースが確認できる記載になっていないのではないかと思います。

# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

 つきましては,このような状況を解消し,無事にデータベースを構築したいのですが,どのように考えればよいか,ご助言をいただけますと幸いです。
 以上,よろしくお願いいたします。

0

1Answer

rails 6.1.4以降にアップグレードするか、Psychを3系にするかで問題が解消するか確認してみてください。

0

Your answer might help someone💌