1
我做了一些遷移,當我嘗試遷移時出現錯誤。 我不知道我犯了什麼錯,我是Laravel移民的新手。Laravel 5.4遷移錯誤
下面是我的移民文件
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateFavouritesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('favourites', function (Blueprint $table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('name_id')->unsigned();
$table->timestamps();
});
Schema::table('favourites', function(Blueprint $table)
{
$table->foreign('user_id')->references('id')->on('users')->onDelete('CASCADE');
$table->foreign('name_id')->references('id')->on('names')->onDelete('CASCADE');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('favourites');
Schema::table('favourites', function(Blueprint $table)
{
$table->dropForeign(['user_id']);
$table->dropForeign(['name_id']);
});
}
}
`和的代碼時,我遷移,這是我得到的錯誤:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table `ugal`.`#sql-187c_52` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `favour
ites` add constraint `favourites_name_id_foreign` foreign key (`name_id`) references `names` (`id`) on delete CASCADE)
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table `ugal`.`#sql-187c_52` (errno: 150 "Foreign key constraint is incorrectly formed")
哪裏錯了,爲什麼呢?