LoginSignup
1
1

More than 3 years have passed since last update.

【Ruby on Rails】db:createができない

Posted at

背景

・RoRでアプリ作成時、データベースをPostgreSQLにして、データベースを作成するために下記コマンドを実行

$ rails db:create

エラー内容

could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Couldn't create 'memo_app_development' database. Please check your configuration.
rails aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/xxx/C/ruby/xxx/memo-app/bin/rails:9:in `<top (required)>'
/Users/xxx/C/ruby/xxx/memo-app/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

やったこと

下のコマンドでポスグレのログが読めるみたいなので確認

$ postgres -D /usr/local/var/postgres

すると、

FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.3.

data dictionaryがなんのことかはよくわからないけど、「data dictionaryの初期化はversion12でされたけど、今インストールされているのはversion13なのでうまくいってません」とのことだった。
いろいろ調べていたらポスグレをアップグレードすれば良いみたいだったので実行

$ brew postgresql-upgrade-database

結果

無事データベースの作成に成功しました。

$ rails db:create
Created database 'memo_app_development'
Created database 'memo_app_test'
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1