2017-11-30 5 views
0

의 열 위치와 고유 제한 조건으로 테이블에 열을 추가합니다. 새로 고침없이 laravel5.2 테이블에 열을 추가하고</p> <p>열이 고유 제한 조건이 있어야하고 해당 컬럼의 위치를 ​​설정할 수 있습니다 시도 laravel 5.2

public function up() 
{ 
    Schema::table('tbl_group_law_master', function($table) { 
    $table->string('group_id')->unique()->after('lm_id'); 
}); 
} 

    public function down() 
    { 
    Schema::table('tbl_group_law_master', function($table) { 
    $table->dropColumn('group_id'); 
    }); 
} 

답변

0

기존 테이블에 새 열을 추가하기위한 새로운 마이그레이션 파일을 만듭니다 작동하지 않습니다. php artisan migrate

- 다음 명령을 실행

public function up() 
{ 
    Schema::table('tbl_group_law_master', function (Blueprint $table) { 
     //if display_name is not added, add this column 
     if(!Schema::hasColumn('tbl_group_law_master','group_id')) { 
      $table->string('group_id', 20)->after('lm_id')->unique(); 
     } 
    }); 
} 

public function down() 
{ 
    Schema::table('tbl_group_law_master', function (Blueprint $table) { 
     //if display_name is not added, add this column 
     if(Schema::hasColumn('tbl_group_law_master','group_id')) { 
      $table->dropColumn('group_id'); 
     } 
    }); 
} 

- 같은

새로운 마이그레이션을 볼 것이다