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

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

我在后端使用 voyager 作为管理面板,在创建 BREAD 时出现此类错误

SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL:
insert into `data_types` (`name`, `display_name_singular`, `display_name_plural`,
`slug`, `icon`, `model_name`, `controller`, `policy_name`, `generate_permissions`,
`details`, `description`, `server_side`, `updated_at`, `created_at`) values (hdept,
Hdept, Hdepts, hdept, , App\Hdept, , , 1, {"order_column":null, "order_display_column":null,
"order_direction":"asc", "default_search_key":null}, , 0, 2019-03-04 12:56:29,
2019-03-04 12:56:29))

型号 (Hdept.php)

namespace App;

use Illuminate\Database\Eloquent\Model;

class Hdept extends Model
{
    protected $fillables = [ 'id'];
}

for bread refernce

这只是意味着您需要在插入新记录时指定 id 的值,或者您需要在 table 定义中提供默认值。

您可以在迁移中定义一个自动递增的 ID:

$table->increments('id');