当我迁移我的数据库时,我会得到这个错误。在ubuntu,我不知道这个错误。但是,如果我将/导入到服务器或MAC,则会出现以下错误。这是我的用户模型。可填充物
protected $fillable = [
'name', 'email', 'password', 'user_type_id', 'verified',
];
我厌倦了migrate:refresh
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
我改变了Schema::defaultStringLength(191);
in AppServiceProvider.php,但它从未起作用。
发布于 2018-03-01 22:40:41
在您的迁移中,您应该使用递增字段:
Schema::create('YourTable', function (Blueprint $table) {
$table->increments('id');
// More fields
});
发布于 2018-03-01 23:43:51
迁移文件中的id类似于:$table->integer('id');
,它不是auto-incrementing
,所以要么自动递增,要么将其添加到$fillable
数组中,并在每次插入时指定id
。
我推荐第一次批准
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
});
https://stackoverflow.com/questions/49063883
复制