The foreign key must be the same type as the referenced key on the other table - i.e. unsigned big integer
$table->unsignedBigInteger('owner_id');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
Full repo here https://github.com/tenzan/laravel-app-01
Please note users table were automatically generated when I was adding authentication.
I'm having this error when running tests, where location should have an owner:
SQLSTATE[HY000]: General error: 3780 Referencing column 'owner_id' and referenced column 'id' in foreign key constraint 'locations_owner_id_foreign' are incompatible. (SQL: alter table `locations` add constraint `locations_owner_id_foreign` foreign key (`owner_id`) references `users` (`id`) on delete cascade)
Locations table migration:
{
Schema::create('locations', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('owner_id');
$table->string('name');
$table->text('description');
$table->timestamps();
$table ->foreign('owner_id')
->references('id')
->on('users')
->onDelete('cascade');
});
}
Users table migration:
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
Regards.
The foreign key must be the same type as the referenced key on the other table - i.e. unsigned big integer
$table->unsignedBigInteger('owner_id');
Please or to participate in this conversation.