mardi 29 août 2017

laravel 5.4 add index to field

I know this can easily be achieved by doing this:

$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->unsignedInteger('gender_id');
$table->date('date_of_birth');
$table->date('active_in_sport');
$table->unsignedInteger('people_type_id');
$table->timestamps();

$table->unique([
    'first_name',
    'last_name'
]);
$table->index('gender_id');
$table->index('people_type_id');

The downside of this is that Laravel first creates the table and than runs an alter table query. At the moment I run into a foreign key error because of this so I'd like to add the index to the field in the create statement. How can I do this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire