I am creating a simple system for school management and I will have a table named 'student_class', where the primary key must be composed of the student id and class id, which are foreign keys of the 'student' and 'class' tables respectively . I created my migration as follows:
public function up()
{
Schema::create('turma_alunos', function (Blueprint $table) {
$table->integer('ID_TURMA_TUR')->unsigned();
$table->foreign('ID_TURMA_TUR')->references('ID_TURMA_TUR')->on('turmas');
$table->integer('ID_ALUNO_ALU')->unsigned();
$table->foreign('ID_ALUNO_ALU')->references('ID_ALUNO_ALU')->on('alunos');
$table->primary(['ID_TURMA_TUR', 'ID_ALUNO_ALU']);
$table->timestamps();
});
}
At the end, the table with the composite primary key was created, but only the student id was left as a foreign key:
Is it possible to do this the way I would like it? How to do this in Laravel?