Laravel5.5で複合インデックスを後から追加する方法

複合インデックスをあとから追加する方法のメモ

postsテーブルに追加するという前提

php artisan make:migration add_index_to_posts_table

migrationファイルが作成されるので

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

class AddIndexToPostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('timelines', function (Blueprint $table) {
            $table->index(['column1', 'column2'], 'インデックス名');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $table->dropIndex('インデックス名');
    }
}

実行

php artisan migrate

シェアする

  • このエントリーをはてなブックマークに追加

フォローする