首页 > 解决方案 > laravel 迁移增量列问题

问题描述

将我的 laravel 项目部署到云(heroku)后,我注意到当我尝试添加新用户或新角色或新东西时 .. 列 id 增加 +10 .. 例如第一个用户 id = 1 ,第二个用户 id = 11

例如这是我的角色表:

public function up()
{
    Schema::create('roles', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name')->unique();
        $table->timestamps();
    });
}

这是我在 mysql workbenck 中的角色表

标签: mysqllaravellaravel-7

解决方案


它与auto_increment_incrementmysql的设置有关。

mysql> SHOW VARIABLES LIKE 'auto_inc%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.04 sec)

auto_increment_increment可能设置为 10。您可以通过执行再次设置为 1;

SET @@auto_increment_increment=1;

在这里查看

编辑:

由于 Heroku 使用cleardb; 使用 cleardb 时无法更改它。这是带有解释的答案


推荐阅读