2017-05-14 18 views
2

私はbigIncrementsにIを変更するとき、私はこのエラーを得た:にerrno:150は "外部キー制約が間違って形成されている" - bigIncrements

.`products` (errno: 150 "Foreign key constraint is incorrectly formed") 

私のコード:

public function up() 
{ 
    Schema::create('products', function (Blueprint $table) { 
     $table->bigIncrements('id')->unsigned(); 
     $table->string('title'); 
     $table->integer('current_buy'); 
     $table->integer('count'); 
     $table->text('short_description'); 
     $table->text('long_description'); 
     $table->tinyInteger('status')->default(0); 
     $table->string('series'); 
     $table->integer('max_buy'); 
     $table->integer('parent_product_id')->nullable()->unsigned(); 
     $table->foreign('parent_product_id')->references('id')->on('products')->onDelete('cascade'); 
     $table->tinyInteger('admin_seen')->default(0); 
     $table->timestamps(); 
    }); 

    DB::update("ALTER TABLE products AUTO_INCREMENT = 1000;"); 
} 

が、コードの下に正常に動作します。

public function up() 
{ 
    Schema::create('products', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->string('title'); 
     $table->integer('current_buy'); 
     $table->integer('count'); 
     $table->text('short_description'); 
     $table->text('long_description'); 
     $table->tinyInteger('status')->default(0); 
     $table->string('series'); 
     $table->integer('max_buy'); 
     $table->integer('parent_product_id')->nullable()->unsigned(); 
     $table->foreign('parent_product_id')->references('id')->on('products')->onDelete('cascade'); 
     $table->tinyInteger('admin_seen')->default(0); 
     $table->timestamps(); 
    }); 

    // DB::update("ALTER TABLE products AUTO_INCREMENT = 1000;"); 
} 

答えて

4

あなたはそれがこの変更を動作させるために、idためbigIncrements()を使用しているので:これに

$table->integer('parent_product_id')->nullable()->unsigned(); 

$table->bigInteger('parent_product_id')->nullable()->unsigned(); 
関連する問題