gpt4 book ai didi

php - 如何在迁移 laravel 5.3 中设置不自动增量?

转载 作者:行者123 更新时间:2023-11-29 02:46:36 25 4
gpt4 key购买 nike

我的代码迁移是这样的:

public function up()
{
Schema::create('satkers', function (Blueprint $table) {
$table->increments('id');
...
});
}

我运行 php artisan migrate。然后,我在数据库管理员中看到。就像这样:enter image description here

我不希望它自动递增,那么我该如何通过迁移文件来实现呢。

我该怎么做?

最佳答案

设置为integer()在迁移中并使用 primary() 设置主键:

$table->integer('id')->unsigned();
$table->primary('id');

另一种方法是define primary key in Eloquent model :

Eloquent will also assume that each table has a primary key column named id. You may define a $primaryKey property to override this convention.

In addition, Eloquent assumes that the primary key is an incrementing integer value, which means that by default the primary key will be cast to an int automatically. If you wish to use a non-incrementing or a non-numeric primary key you must set the public $incrementing property on your model to false.

关于php - 如何在迁移 laravel 5.3 中设置不自动增量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41375749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com