我有这个迁移:
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?
答案 0 :(得分:0)
// Your migration here:
Schema::create('players', function (Blueprint $table) {
//
});
//then set auto-increment to 1000
DB::update("ALTER TABLE players AUTO_INCREMENT = 1000;");
请参阅:Set Auto Increment field start form 1000 in migration laravel 5.1
答案 1 :(得分:0)
你可以使用这样的东西。
ALTER table <table name> AUTO_INCREMENT = <initial value>
表被截断AUTO_INCREMENT值不会重置。在下次插入时,它将考虑下一个递增值,即使在那些情况下我们可以执行上述查询来重置自动增量值