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

标签 php mysql laravel migration laravel-5.3

我的代码迁移是这样的:

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/

相关文章:

php - 对不同表中的相同字段进行排序

php - 如何从 paypal ipn 中分解产品 ID 和数量字符串

c# - 如何获取刚刚插入的记录的 pkey 值(自动增量)?

php - Laravel 为 2 列连接同一个表

linux - 启动 Vagrant 时连接超时

php - 在 PHP 中解析 Wikipedia API json

php - 在 laravel 中从 routeserviceprovider 创建路由时中间件不工作

MySQL - 通过使用多个 WHERE/OR 子句连接多个表来返回单个记录

php - 检查结果是否为整数/varchar/等。 SQL执行期间?

PHP Laravel 如何使用两个表进行排序