I started working on small project using Laravel latest version, i try to make a foreign key between two table ( Buildings and Appartmens ) but i get an error message contain :
("SQLSTATE[HY000]: General error: 1005 Can't create table `project`.`apartments` (errno: 150 "Foreign key constraint is incorrectly formed")")
this is my buildings
table schema :
Schema::create('buildings', function (Blueprint $table) {
$table->id();
$table->string('address');
$table->timestamps();
});
this is my apartments
table schema :
Schema::create('apartments', function (Blueprint $table) {
$table->id();
$table->string('number');
$table->integer('monthly_price');
$table->integer('rooms');
$table->integer('bath_room');
$table->string('description');
// Foreign Key
$table->foreignId('building_id')->constrained('buildings');
// Record Times
$table->timestamps();
});