2023_12_05_121003_create_bands_table ................................................................................................... 14ms DONE
2023_12_05_121003_create_songs_table ................................................................................................... 83ms FAIL
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1005 Can't create table `spotify-remake`.`songs` (errno: 150 "Foreign key constraint is incorrectly formed") (Connection: mysql, SQL: alter table `songs` add constraint `songs_album_id_foreign` foreign key (`album_id`) references `albums` (`id`) on delete cascade)
at vendor\laravel\framework\src\Illuminate\Database\Connection.php:822
818▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
819▕ );
820▕ }
821▕
➜ 822▕ throw new QueryException(
823▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
824▕ );
825▕ }
826▕ }
1 vendor\laravel\framework\src\Illuminate\Database\Connection.php:580
PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `spotify-remake`.`songs` (errno: 150 "Foreign key constraint is incorrectly formed")")
2 vendor\laravel\framework\src\Illuminate\Database\Connection.php:580
PDOStatement::execute()
#Migration problemo
3 messages · Page 1 of 1 (latest)
Create_bands_table : <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('bands', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->text('members');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('bands');
}
};
Create_songs_table : <?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('songs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->unsignedBigInteger('album_id');
$table->unsignedBigInteger('band_id');
$table->integer('length');
$table->timestamps();
$table->foreign('album_id')->references('id')->on('albums')->onDelete('cascade');
$table->foreign('band_id')->references('id')->on('bands')->onDelete('cascade');
});
}
public function down()
{
Schema::dropIfExists('songs');
}
};
Create_albums_table :
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('albums', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->unsignedBigInteger('band_id');
$table->timestamps();
$table->foreign('band_id')->references('id')->on('bands')->onDelete('cascade');
});
}
public function down()
{
Schema::dropIfExists('albums');
}
};