2016-09-07 14 views
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'); 
} 
} 

答えて

0

テーブルをInnodbエンジンに設定しようとします。 テーブル作成の最後にこれを追加します。

Schema::create('comments',function($newTable){ 
//The other fields 
    $newTable->engine = "InnoDB";   
}); 
関連する問題