multiple primary key laravel

1

** Hi, I'm new to laravel and I'd like to know how to define multiple primary keys in laravel, since this way I get an error.

Schema :: create ('schedule', function (Blueprint $ table) {

        $table->string('dia');
        $table->string('hora');
        $table->integer('sala');
        $table->increments('id_asignatura');
        $table->primary(['dia', 'hora', 'sala']);
        $table->foreign('id_asignatura')->references('id_asignatura')->on('asignatura');
        $table->timestamps();
    }); **
    
asked by Nicol Valeska 06.10.2018 в 22:25
source

1 answer

1

Unfortunately Laravel does not support composite primary keys. Maybe it would be best to create a unique index for those three columns, something like this:

$table->unique( array('dia','hora', 'sala') );

and create an autoincremental primary key:

$table->bigIncrements('id');
$table->primary('id');

I hope it serves you.

    
answered by 06.10.2018 в 22:27