Hi, I'm trying to add a pivot table and have foreign keys in it but I always get this error:
SQLSTATE[HY000]: General error: 3780 Referencing column 'booking_id' and referenced column 'id' in foreign key constraint 'booking_service_booking_id_foreign' are incompatible. (SQL: alter table `booking_service` add constraint `booking_service_booking_id_foreign` foreign key (`booking_id`) references `bookings` (`id`) on delete cascade)
Here is my CreateBookingServiceTable:
public function up()
{
Schema::create('booking_service', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('booking_id');
$table->unsignedInteger('service_id');
$table->timestamps();
$table->unique(['booking_id', 'service_id']);
});
Schema::table('booking_service', function($table) {
$table->foreign('booking_id')->references('id')->on('bookings')->onDelete('cascade');
$table->foreign('service_id')->references('id')->on('services')->onDelete('cascade');
});
}
And here is my CreateBookingsTable
public function up()
{
Schema::create('bookings', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
});
}
And here is my CreateServicesTable
public function up()
{
Schema::create('services', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('carSize');
$table->string('description');
$table->timestamps();
});
}