【发布时间】:2017-10-04 20:12:43
【问题描述】:
我正在尝试在 laravel 中创建表 'teams' 和 'competitions' 但是当我运行 migrate 命令时,我得到以下信息: errno: 150 "Foreign key constraint is wrongly forms"
Schema::create('competitions', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('team_name');
$table->foreign('team_name')->references('name')->on('teams')->onDelete('cascade');
$table->timestamps();
});
Schema::create('teams', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->string('place');
$table->string('competition')->nullable();;
$table->foreign('competition')->references('name')->on('competitions')->onDelete('set null');
$table->timestamps();
});
【问题讨论】: