Laravel Field'id'没有默认迁移?

问题描述 投票:0回答:2

当我迁移我的数据库时,我收到此错误。在ubuntu我不会得到这个错误。但是,如果我迁移/导入到服务器或MAC我得到这个波纹管错误。这是我的用户模型。可填充的stuf

protected $fillable = [
        'name', 'email', 'password', 'user_type_id', 'verified',
    ];

我厌倦了迁移:刷新

Rolling back: 2014_10_12_000000_create_users_table
Rolled back:  2014_10_12_000000_create_users_table


 [Illuminate\Database\QueryException]
 SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL: insert into `migrations` ('migration', 'batch') valu
 es (2014_10_12_000000_create_users_table, 1))



 [PDOException]
 SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value

我在AppServiceProvider.php中更改了Schema::defaultStringLength(191);,它从未奏效。

mysql laravel
2个回答
1
投票

在迁移中,您应该使用增量字段:

Schema::create('YourTable', function (Blueprint $table) {
        $table->increments('id');
        // More fields
});

0
投票

您的迁移文件中的ID类似于:$table->integer('id');,它不是auto-incrementing,因此您可以将其自动增量或将其添加到$fillable数组并在每个插入上指定id

我推荐第一种方法

    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
    });
© www.soinside.com 2019 - 2024. All rights reserved.