General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constra int 'posts_user_id_foreign' are incompatible. code example

Example 1: SQLSTATE[HY000]: General error: 3780 Referencing column 'role_id' and referenced column 'id' in foreign key constraint 'user_role_id foreign' are incompatible.

As the name says the referenced foreign key and the id in the table are not of 
same type. 

Example : 

// user_id foreign key referenced table
$table->bigInteger('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');


// Then inside users table
$table->bigIncrements('id')->unsigned()->index();

Example 2: General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'blog_posts_user_id_foreign' are incompatible.

$table->bigInteger('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

Tags:

Sql Example