This is my migration `
<?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']);
});
}
}
` and when i want to migrate, this error is shows up: [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")
Where is the mistake,and why?via Wolffyx