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 Personen extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('personen', function (Blueprint $table) {
$table->increments('persoon_id');
$table->timestamps();
$table->string('voornaam');
$table->string('achternaam');
$table->string('email')->unique();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
I tried ->unsigned()
but that doesn't work either.
via Sinan Samet