Laravel Migration Foreign key constraint is incorrectly formed

Ask by Save Pongsiri 1 year ago

When creating a new table in Laravel. A migration will be generated like:


Instead of (in older Laravel versions):


When using bigIncrements the foreign key expects a bigInteger instead of an integer. So your code will look like this:

public function up()
        Schema::create('meals', function (Blueprint $table) {
            $table->unsignedBigInteger('user_id'); //changed this line
            $table->unsignedBigInteger('category_id'); //changed this line



You could also use increments instead of bigIncrements like Kiko Sejio said.

The difference between Integer and BigInteger is the size:

  • int => 32-bit
  • bigint => 64-bit

0 Replies

Your Reply