0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

作成したLaravelアプリケーションにPosgresqlを接続する

Posted at

前提条件

php7.2(brewでインストールしています)
Laravel
Postgres12.3(こちらもbrewでインストールしています。)
Laravelのトップページが開いているところからやります。
目標は、posgresqlに接続して、php aritisan migrateでDBを作るまで

その1 .envファイルで指定したユーザーと同じユーザー(ロール)をpsql側で作る

# .env
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=sample  #その2
DB_USERNAME=default #その1 このユーザーをpsql側で作成する
DB_PASSWORD=secret
$ createuser default

その2 .envファイルで指定したDBと同じDBをpsql側で作る

$ createdb sample -O default

つくれたかチェックします。

$ psql -l

最終章、 Laravelプロジェクトのあるディレクトリに入り、php artisan migrateを実行します。

$ cd Laravelプロジェクト
$ php artisan migrate
Rolling back: 2020_05_29_072511_create_problems_table
Rolled back:  2020_05_29_072511_create_problems_table
Rolling back: 2020_05_22_023512_add_column_to_users_table
Rolled back:  2020_05_22_023512_add_column_to_users_table
Rolling back: 2020_05_07_115046_create_song_tag_table
Rolled back:  2020_05_07_115046_create_song_tag_table
Rolling back: 2020_04_19_234148_create_tags_table
Rolled back:  2020_04_19_234148_create_tags_table
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?