如何使外键与int类型相同?

I have the following migration file declared in laravel:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products' , function($table){
            $table->increments('id');
            $table->integer('category_id');
            $table->string('title');
            $table->text('description');
            $table->decimal('height' , 6 , 2);
            $table->decimal('width' , 6 , 2);
            $table->decimal('length' , 6 , 2);
            $table->string('color');
            $table->string('material');
            $table->timestamps();

        });

        Schema::table('products' , function($table){
            $table->foreign('category_id')->references('id')->on('categories');
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('products');
    }

}

now when i run php artisan migrate

i get an error , because the id in categories is int(10) and the categories_id I.E.

$table->foreign('category_id')->references('id')->on('categories');

is int(11) how do i make both int(10) ?

I would guess that your previous migrations were run on a previous version of Laravel. If that's the case, you can simply modify the column type of categories.id to int(11) directly in the DB.

Otherwise, you could use a Raw Query to add the column using INT(10).

To confirm the hypothesis that a version change caused this, you could run ALL migrations in an empty DB and see if you have the same issue.

Schema::table('products', function($table)
{
    $table->integer('id, 10');
});