有没有办法使用Schema Builder迁移在Laravel 4中的表上设置主键的自动增量初始值?
我想将表的id设置为从100开始。我知道可以使用带有ALTER TABLE MY_TABLE AUTO_INCREMENT = 111111;
的纯SQL,但我想使用Laravel Migrations维护数据库版本。
有什么想法吗?
答案 0 :(得分:22)
我担心Laravel仍无法改变自动增量值,但你可以创建一个迁移并在其中执行:
<?php
use Illuminate\Database\Migrations\Migration;
class MyTableMigration extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$statement = "
ALTER TABLE MY_TABLE AUTO_INCREMENT = 111111;
";
DB::unprepared($statement);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
答案 1 :(得分:1)
<强>的Postgres 强>:
class MyTableMigration extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$statement = "ALTER SEQUENCE my_table RESTART WITH 111111";
DB::unprepared($statement);
}
...
}