1
Laravel 5はマイグレーションファイルに外部キーを作成しません。 ここに記載されているドキュメント https://laravel.com/docs/5.3/bladeに従っており、動作しません。テーブルは制約なしで作成されますLaravel 5の外部キーは作成されません
<?php
use Carbon\Carbon;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class Comments extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments',function($newTable){
$newTable->increments('id');
$newTable->integer('painting_id')->length(10)->unsigned();
$newTable->integer('user_id');
$newTable->text('comment');
$newTable->date('crated')->default(Carbon::now());
$newTable->timestamps();
});
Schema::table('comments',function($table){
$table->foreign('painting_id')->references('id')->on('paintings')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('comments');
}
}