Laravel SQLSTATE[HY000]:一般错误:1364字段';id';不';没有默认值

Laravel SQLSTATE[HY000]:一般错误:1364字段';id';不';没有默认值,laravel,Laravel,为什么在live server中显示此错误,但在localhost中没有显示错误 SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL: insert into `users` (`role_id`, `name`, `username`, `email`, `password`, `updated_at`, `created_at`) values (2, lino, lino, li

为什么在live server中显示此错误,但在localhost中没有显示错误

SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL: insert into `users` (`role_id`, `name`, `username`, `email`, `password`, `updated_at`, `created_at`) values (2, lino, lino, lino@gmail.com, $2y$10$8i2ucs2nRv.ggnRHNmiK/.QPNJ4uRNwjRZCg5D6ILUMFvyr5.qyXW, 2020-01-03 21:36:49, 2020-01-03 21:36:49))

您的用户表id不是自动递增的。使其自动递增。

“为什么此错误在live server中显示,但在localhost中没有错误?”--可能是因为您的数据库在localhost上的配置与在服务器上的配置不同。我从localhost导入了确切的数据库。除了注册,一切都正常。您应该验证您的数据库结构。-是否将
users
table
id
列设置为autoincrometing
protected function create(array $data)
    {
        return User::create([
            'role_id' => 2,
            'name' => $data['name'],
            'username' => str_slug($data['username']),
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }