あまりぱっとしたものが検索あがってこなかったので自分で記事作成。
テーブル名はexamples、インデックスを追加したいカラムをhoge_fugaとします。
$ php artisan make:migration add_index_examples --table=examples
を実行して生成されたmigrationファイル(e.g. 2019_01_23_123456_add_index_examples) を開いて
up()には
$table->index('hoge_fuga');
down()には
$table->dropIndex('examples_hoge_fuga_index');
を追加します。downに追記するインデックス名は テーブル名_カラム名_index になります。
合わせると下記のようになります。
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('examples', function (Blueprint $table) {
$table->index('hoge_fuga');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('examples', function (Blueprint $table) {
$table->dropIndex('examples_hoge_fuga_index');
});
}
$ php artisan migrate --pretend
でテスト実行して問題ないかを確認、問題なければ
$ php artisan migrate
を実行して実際にカラム追加して完了です。