Laravel8 migrate command

2023. 7. 20. 18:06PHP/Laravel8.X

728x90

https://medium.com/@rakshithvasudev/laravel-migrations-what-are-they-why-use-them-how-to-use-203769a917c3

 


https://stackoverflow.com/questions/49056542/how-does-laravels-migration-up-and-down-method-work

php artisan migrate will run your up() method.
php artisan migrate:rollback will run your down() method.

 

example-app>php artisan make:migration create_user_table
Created Migration: 2022_11_14_071453_create_member_table

example-app>php artisan make:migration member_table
Created Migration: 2022_11_14_071510_member_table

example-app>php artisan migrate 
Migrating: 2022_11_14_071453_create_member_table
Migrated:  2022_11_14_071453_create_member_table (14.24ms)
Migrating: 2022_11_14_071510_member_table
Migrated:  2022_11_14_071510_member_table (0.03ms)

 

php artisan make:migration create_visitors_table
php artisan make:migration create_counters_table
// create_테이블이름_끝자리복수형_table
// db 테이블 이름은 끝자리 복수형으로 써야함
// 테이블 뒤에 세미콜론쓰면 그것까지 테이블 이름 되어버림

asdf\database\migrations\2023_01_31_085716_create_visitors_table.php
// up() 정의

php artisan migrate
// 위에서 정의한 마이그레이션 설정대로 db 테이블 생성

Cf.
php artisan migrate:rollback
// db에 테이블 생성된 것 실행취소 하고싶을 때
--> migration rollback을 할 경우 create_table.php 는 그대로 있고
DB에서 테이블 생성된 부분만 롤백 됨.

롤백 후에 수정한 create_table.php 대로 다시 테이블 생성하려면
Php artisan migrate만 다시 하면 됨.


php artisan cache:clear
// 캐시 삭제

728x90
반응형