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

时间:2018-03-02 06:31:48

标签: mysql laravel

当我迁移我的数据库时,我收到此错误。在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);,但它从未奏效。

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

您的迁移文件中的

id类似于:$table->integer('id');,而不是auto-incrementing,因此您要么将其自动增加,要么将其添加到$fillable数组并指定id on每个插页。

我推荐第一个approch

    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
    });