0
I am creating a simple system for school management and I will have a table called 'class students', where the primary key should be composed by the student id and class id, which are foreign keys of the 'students' and 'classes' 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();
});
}
In the end, the table with the composite primary key was created, but only the student’s id was a foreign key:
Is it possible to do it the way I would like? How to do it in Laravel?
I decided to put an answer, maybe it helps to understand that the relationships were created correctly.
– novic