General error: 1215 Cannot add foreign key constraint
rrrhys opened this issue · comments
Hi,
Thanks for the great package.
Using Laravel ^8.12, the initial migration fails with an error:
General error: 1215 Cannot add foreign key constraint (SQL: alter table `watch` add constraint `watch_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade)
Changing the user_id
column in the initial migration from integer
to bigInteger
allows the migration to run correctly.
$table->bigInteger('user_id')->unsigned()->index();
I hope this helps someone in the future - please let me know if a PR would be useful.
Ah, has the default users.id
column been updated to a bigInteger
in Laravel 8 by default in the user migration?
Looks like it landed in Laravel 7.
Command | Description |
---|---|
$table->id(); | Alias of $table->bigIncrements('id'). |
from https://laravel.com/docs/7.x/migrations
Default CreateUsersTable
migration now looks like:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
// snip
$table->timestamps();
});
}
So I would assume everyone who's tried to install this package with > Laravel 7 has had this issue? lol
Thanks for reporting this.
Please PR it and I will merge it in.
Thanks @rrrhys