From Laravel 5.x to Laravel 6 by the default the migrations has a little change now all id columns has a type of big increments unsigned:
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements();
...
});
Then the foreign key requires to be an "UnsignedBigInteger":
Schema::create('posts', function (Blueprint $table) {
$table->unsignedBigInteger('user_id');
...
});
A little note on Laravel 7.
It adds a helper method to be an "alias" of "UnsignedBigInteger", now in your migrations by default you will have the id column:
Schema::create('users', function (Blueprint $table) {
$table->id();
...
});
The id method in is just an alias of the same "UnsignedIncrements", so nothing has change is just a method to make more readable the migrations code.
Define a foreign keys with Laravel 7:
Schema::create('posts', function (Blueprint $table) {
$table->foreign_id('user_id')->references('id')->on('users');
...
});
But you have an even better way o add this foreign key, if you follow the convention, (id is the name of column id and use {tablename}_id as the foreign key):
Schema::create('posts', function (Blueprint $table) {
$table->foreign_id('user_id')->constrained();
...
});
That's all, thanks for reading.