I have tried add foreign key constraint using migrations. The migration completes without any error. However, when the database is checked, the foreign key constraint is not added to the table. Other things specified in the migrations work fine except of FK constraint.
My pivot table with FKs:
Schema::create('book_author', function (Blueprint $table) {
$table->integer('book_id')->unsigned();
$table->integer('author_id')->unsigned();
$table->foreign('book_id')->references('id')->on('book')->onDelete('restrict')->onUpdate('cascade');
$table->foreign('author_id')->references('id')->on('author')->onDelete('restrict')->onUpdate('cascade');
$table->primary(['book_id','author_id']);
});
Schema::enableForeignKeyConstraints();
Author table:
Schema::create('author', function (Blueprint $table) {
$table->increments('id');
$table->string('email', 250)->unique();
});
Book table:
Schema::create('book', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
});
Is there anything I'm missing here?