I am trying to create the tables 'teams' and 'competitions' in laravel but when I run the migrate command, I get the following: errno: 150 "Foreign key constraint is incorrectly formed"
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();
});