Yom*_*ham 4 database-migration laravel eloquent laravel-migrations
我想写一个 Laravel Migration 自动增量 ID 作为主键。我想用另一个值而不是 1 来启动此 ID。我该怎么做?
迁移up()函数:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->string('phone');
$table->rememberToken();
$table->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud)
小智 11
从 Laravel 8.x 开始,您现在可以在迁移中使用它:
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id()->startingValue(1200);
});
}
Run Code Online (Sandbox Code Playgroud)
来源: https: //laravel-news.com/laravel-auto-increment
| 归档时间: |
|
| 查看次数: |
9521 次 |
| 最近记录: |