Laravel 5不会在我的迁移文件上创建外键: 我按照这里的文档 https://laravel.com/docs/5.3/blade它不起作用。在没有约束的情况下创建表
<?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 :(得分:0)
尝试将表设置为Innodb引擎。 在表创建结束时添加它。
Schema::create('comments',function($newTable){
//The other fields
$newTable->engine = "InnoDB";
});