I am creating a many to many relationship in Laravel 7 but get errors when trying to create my pivot table - Error is
SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and referenced column 'id'
in foreign key constraint 'groups_users_table_user_id_foreign' are incompatible.
(SQL: alter table `groups_users_table` add constraint `groups_users_table_user_id_foreign`
foreign key (`user_id`) references `users` (`id`) on delete cascade)
My pivot table migration -
Schema::create('groups_users_table', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('users_id');
$table->unsignedBigInteger('groups_id');
$table->foreign('users_id')->references('id')->on('users')
->onDelete('cascade');
$table->foreign('groups_id')->references('id')->on('groups')
->onDelete('cascade');
$table->timestamps();
});
Groups table -
public function up()
{
Schema::create('groups', function (Blueprint $table) {
$table->increments('id');
$table->text('name', 100);
$table->text('description', 144);
$table->timestamps();
});
}
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
show create table users
results in
CREATE TABLE `users` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`email_verified_at` timestamp NULL DEFAULT NULL,
`password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `users_email_unique` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
What is causing this issue?