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');
}
}