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 1 year has passed since last update.

Dockerで構築したpostgresDBにlaravelでmigration

Posted at

目標

Dockerで構築したpostgresDBにlaravelでmigrationする

前提

環境

  • Windows10 wsl2 Ubuntu
  • Docker version 20.10.17, build 100c701
  • postgresql14
  • adminer 4.8.1
  • laravel9
  • Composer version 2.3.7
  • PHP 8.0.12 (cli) (built: Oct 19 2021 11:21:05) ( ZTS Visual C++ 2019 x64 )
    ※xampを用いてインストール

作業手順

  1. laravelのプロジェクトを作成
    composer create-project laravel/laravel:^9 [project_name]
    
  2. .envファイルの編集
    .env
    (略)
    # mysql 
    # DB_CONNECTION=mysql
    # DB_HOST=127.0.0.1
    # DB_PORT=3306
    # DB_DATABASE=laravel
    # DB_USERNAME=root
    # DB_PASSWORD=
    
    # postgres
    DB_CONNECTION=pgsql
    DB_HOST=127.0.0.1
    DB_PORT=5432
    DB_DATABASE=postgres
    DB_USERNAME=postgres
    DB_PASSWORD=test
    
    (略)
    
  3. dockerでpostgresが起動しているか確認
    ----%docker ps
    CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS          PORTS                    NAMES
    10f74fe67832   postgres:14   "docker-entrypoint.s…"   25 seconds ago   Up 24 seconds   0.0.0.0:5432->5432/tcp   db_db_1
    
  4. マイグレーションの実行
    C:\Users\user_name\dev\laravel\test>php artisan migrate
    
       INFO  Preparing database.
    
      Creating migration table ..................................... 26ms DONE
    
       INFO  Running migrations.
    
      2014_10_12_000000_create_users_table ......................... 37ms DONE
      2014_10_12_100000_create_password_resets_table ............... 22ms DONE
      2019_08_19_000000_create_failed_jobs_table ................... 30ms DONE
      2019_12_14_000001_create_personal_access_tokens_table ........ 48ms DONE
    
  5. adminerで反映されているか確認
    http://localhost:8080/
    image.png
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?