"Laravel 데이터베이스: 마이그레이션"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-==참고 자료== +==참고==))
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
5번째 줄: 5번째 줄:
==마이그레이션 생성==
==마이그레이션 생성==
* artisan명령을 통한 마이그레이션 생성
* artisan명령을 통한 마이그레이션 생성
<source lang='bash'>
<syntaxhighlight lang='bash'>
php artisan make:migration create_tasks_table --create=tasks
php artisan make:migration create_tasks_table --create=tasks
</source>
</syntaxhighlight>


* 마이그레이션 작성(수정)
* 마이그레이션 작성(수정)
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php


32번째 줄: 32번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>
* 마이그레이션 확인 후 수행
* 마이그레이션 확인 후 수행
<source lang='bash'>
<syntaxhighlight lang='bash'>
php artisan migrate:status
php artisan migrate:status
php artisan migrate
php artisan migrate
</source>
</syntaxhighlight>


==DB 마이그레이션 변경==
==DB 마이그레이션 변경==
* artisan 명령을 통한 DB에 생성된 마이그레이션 삭제후 재 마이그레이션
* artisan 명령을 통한 DB에 생성된 마이그레이션 삭제후 재 마이그레이션
* 리셋, 마이그레이션 과정을 거치기 때문에 DB의 모든 데이터가 삭제됨을 주의 할 것
* 리셋, 마이그레이션 과정을 거치기 때문에 DB의 모든 데이터가 삭제됨을 주의 할 것
<source lang='bash'>
<syntaxhighlight lang='bash'>
php artisan migrate:refresh
php artisan migrate:refresh
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:57 판

1 개요

라라벨 Database Migration
라라벨 DB 마이그레이션

2 마이그레이션 생성

  • artisan명령을 통한 마이그레이션 생성
php artisan make:migration create_tasks_table --create=tasks
  • 마이그레이션 작성(수정)
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTasksTable extends Migration
{
    public function up()
    {
        Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::drop('tasks');
    }
}
  • 마이그레이션 확인 후 수행
php artisan migrate:status
php artisan migrate

3 DB 마이그레이션 변경

  • artisan 명령을 통한 DB에 생성된 마이그레이션 삭제후 재 마이그레이션
  • 리셋, 마이그레이션 과정을 거치기 때문에 DB의 모든 데이터가 삭제됨을 주의 할 것
php artisan migrate:refresh

4 같이 보기

5 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}