3

I am creating some database tables in my OctoberCMS plugin, and in these tables I want to use some indexes. The problem is that these indexes don't get created, de tables get created without the indexes.

Schema::create('table', function ($table) {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->text('textField')->index();
        $table->timestamps();
    });

Why this is/could be?

EDIT: In light of a comment I want to mention that this is not just occurring on text fields but also on integer fields.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    I think TEXT columns do not support these indices. If you are looking for a FULLTEXT index, see here: https://laracasts.com/discuss/channels/general-discussion/fulltext-indexes-at-migrations – Alex Guth Jun 29 '17 at 13:25
  • Thanks, but i found out its not only the text columns that don't work. When i try to create an index on an integer it doesn't work either. I will use your solution for the text fields though, thank you very much for helping. – Jasper de Vries Jun 30 '17 at 07:59
  • What database system and version are you using? – Nick May 29 '18 at 06:01

1 Answers1

0

Try in this way:

Schema::create('table', function ($table) {
    $table->engine = 'InnoDB';
    $table->increments('id');
    $table->text('textField');
    $table->index(['text_field'])
    $table->timestamps();
});
Marco
  • 712
  • 1
  • 10
  • 23