Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使外键与int类型相同?_Php_Laravel 4_Database Migration - Fatal编程技术网

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

Php 如何使外键与int类型相同?,php,laravel-4,database-migration,Php,Laravel 4,Database Migration,我在laravel中声明了以下迁移文件: <?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateProductsTable extends Migration { /** * Run the migrations. * * @return void */ public fu

我在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');
    }

}

int(11)
如何使两者都为int(10)

我猜您以前的迁移是在以前版本的Laravel上运行的。如果是这种情况,您可以直接在数据库中将
categories.id
的列类型修改为
int(11)

否则,您可以使用
INT(10)
来添加列


要确认版本更改导致此问题的假设,您可以在空数据库中运行所有迁移,并查看是否存在相同问题。

我猜您以前的迁移是在以前版本的Laravel上运行的。如果是这种情况,您可以直接在数据库中将
categories.id
的列类型修改为
int(11)

Schema::table('products', function($table)
{
    $table->integer('id, 10');
});
否则,您可以使用
INT(10)
来添加列

要确认版本更改导致此问题的假设,可以在空数据库中运行所有迁移,并查看是否存在相同的问题

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