I get the error:
SQLSTATE[HY000]: General error: 1005 Can't create table
monkeybussiness
.#sql-db0_17
(errno: 150 "Foreign key co nstraint is incorrectly formed")
while the columns are identical as far as I know. Why is this happening?
Events migrations file:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEventsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('events', function (Blueprint $table) {
$table->increments('afspraak_id');
$table->timestamps();
$table->string('titel');
$table->integer('persoon_id');
$table->foreign('persoon_id')->references('persoon_id')->on('personen');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('events');
}
}
Personen migrations file:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEventsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('events', function (Blueprint $table) {
$table->increments('afspraak_id');
$table->timestamps();
$table->string('titel');
$table->integer('persoon_id')->unsigned();
$table->foreign('persoon_id')->references('persoon_id')->on('personen');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('events');
}
}
I tried ->unsigned()
but that doesn't work either.
via Sinan Samet