2017-06-01 120 views
0

開始我有這樣的遷移:自動遞增列ID不從1

public function up() 
{ 
    Schema::create('players', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->char('country_code',2); 
     $table->integer('unoi_id'); 
     $table->string('first_name'); 
     $table->string('last_name'); 
     $table->char('gender', 1); 
     $table->timestamp('birthdate'); 
     $table->integer('school_id'); 
     $table->string('school_period'); 
     $table->string('school_level'); 
     $table->integer('points'); 
     $table->timestamps(); 
    }); 
    Schema::table('players', function(Blueprint $table){ 
     $table->foreign('country_code')->references('country_code')->on('countries'); 
    }); 
} 

當我創建一個新的記錄在ID的列中的值不上1開始。它開始在像321654然後每次增加1。

我的問題是:我能做些什麼來設置默認值爲1?

+1

https://stackoverflow.com/questions/8923114/how-to-reset-auto- increment-in-mysql laravel有一個遷移新鮮命令:https://laravel-news.com/migrate-fresh – mkaatman

+0

migrate:fresh是Laravel 5.5。目前Laravel的穩定版本是5.4 – Brad

+0

謝謝。我從來沒有想過直接用mysql命令做。 –

回答

0

您可以使用這樣的事情。

ALTER table <table name> AUTO_INCREMENT = <initial value> 

表被截斷AUTO_INCREMENT值不會重置。在下一次插入時會考慮下一個遞增值,即使在這些情況下,我們也可以執行上述查詢來重置自動遞增值