如何在mysql表中建立多个索引

问题描述 投票:0回答:1

我有此迁移的产品表:

Schema::create('products', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('code');
        $table->bigInteger('price');
        $table->string('slug');
        $table->text('description');
        $table->text('images');
        $table->string('tags');
        $table->integer('viewCount')->default(0);
        $table->integer('commentCount')->default(0);
        $table->integer('stockCount')->default(0);
        $table->integer('sailedCount')->default(0);

        $table->boolean('specialSail')->default(false);

        $table->integer('size_id')->unsigned();
        $table->foreign('size_id')->references('id')->on('sizes')->onDelete('cascade');
        $table->integer('color_id')->unsigned();
        $table->foreign('color_id')->references('id')->on('colors')->onDelete('cascade');

我想同时使用3个colume(code,size_id,color_id)作为索引,但我有一个具有相同名称和相同代码但大小不同的产品。

laravel
1个回答
0
投票

如果使用InnoDB存储引擎,则无需为此创建索引。 InnoDB将自动创建索引。

您可以编辑您的/config/database.php文件,搜索mysql条目并进行更改:

'engine' => null,

to

'engine' => 'InnoDB',

这使您不必为每个模式添加$table->engine = "InnoDB";

您可以通过以下方式创建索引:

$table->string('slug')->index();

或,

$table->index('slug');
© www.soinside.com 2019 - 2024. All rights reserved.